; lh>c @sdZddd!Zddd!Zddd!ZdkZdklZd klZd k l Z d k l Z d k l Z d k l Z dkZdkZdklZdklZlZdklZdklZdklZdZdZdZdZdZdZdZ dddddddddZ!ede"Z#dddddddde$e$d Z%ddddddddd!Z&d"ee efd#YZ'ei(e'dS($s $RCSfile: XSLTMethod.py,v $ ZopeXMLMethods provides methods to apply to Zope objects for XML/XSLT processing. XSLTMethod associates XSLT transformers with XML documents. XSLTMethod automatically transforms an XML document via XSLT, where the XML document is obtained from another Zope object (the 'source' object) via acquisition. Author: Craeg Strong Modified by Philipp von Weitershausen Release: 1.0 $Id: XSLTMethod.py,v 1.55 2003/03/30 03:45:47 cstrong Exp $ s $Name: $iis$Date: 2003/03/30 03:45:47 $s$Revision: 1.55 $i N(s SimpleItem(s CatalogAware(sPropertyManager(s IXSLTMethod(sProcessorChooser(sGeneratorRegistry(s MessageDialog(saq_bases aq_parent(sClassSecurityInfo(smapply(sPageTemplateFilesViewsEdits FTP accesssAccess contents informationsManage XML MethodscCstt|do |itj o|||Snit|do |itj ot|if|Sn2t|ot |Snd|}t |dS(s= Get the result of an object as if it were published s__call__s index_htmls-Error, unable to obtain source from object %sN( shasattrsaq_basesobjs__call__sNonesREQUESTs index_htmlsmapplyscallablesapplysnamesmessages Exception(snamesobjsREQUESTsmessage((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysgetPublishedResult:s&   cCsd}t}|}|i}xv|tjoh|io(|i|}|o|d}q`n|tjo%||jotSqt |}q!q!W|SdS(s Find an instance of CacheManager to use (optionally, provided the caching property is set to 'on') CacheManager is purely optional. If it is present, caching may be done. If applicable, the XSLTMethod will use the CacheManager it finds via this method The current policy is as follows: use the first cache manager found by acquisition. Alternatively, a more complex policy could be used such as a) looking in some predefined place, where the place could be specified in some property (a la Zope3 explicit acquisition), or b) finding all cache managers in the ZODB and presenting a list for selection by the user. For right now, we don't want to over-engineer the damn thing. CKS 8/4/2002. sXML Method Cache ManageriN( smetaTypesNonescmsselfsfoldersgetPhysicalRootsrootsisPrincipiaFolderishs objectValuess cacheManagerss aq_parent(sselfscmsmetaTypes cacheManagerssfoldersroot((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysfindCacheManagerOs      ss text/htmlsonic Cs8|idi||||||||| ||SdS(s This is a convenience factory method for creating an instance of XSLTMethod. It returns the object created, and may therefore be more convenient than the addXSLTMethod() method it calls. It is used by the unit testing programs. sZopeXMLMethodsN( sfoldersmanage_addProducts addXSLTMethodsidstitles descriptionsselected_processorsxslTransformerIds content_types behave_likescachings debugLevel( sfoldersidstitles descriptionsselected_processorsxslTransformerIds content_types behave_likescachings debugLevel((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys addInstances s www/create.ptc  Csy|i||||||||| d|d}| t jodSny|i} Wn| d} nX| ddjo(d| |f} | ii| dn| ii| d WnJtj o>} t| }|id d td d d|ddSnXdS(s Factory method to create an instance of XSLTMethod, called from a GUI in the Zope Management Interface. It calls addXSLTMethod to actually do the work. sSuccessfully created s XSLTMethod object.NsURL1ssubmits Add and Edit s%s/%ss/manage_editForms /manage_mains s
stitlesErrorsmessagesactions manage_main(sselfs addXSLTMethodsidstitles descriptionsselected_processorsxslTransformerIds content_types behave_likescachings debugLevelsmessagesREQUESTsNonesDestinationURLsurlsRESPONSEsredirects Exceptionsesstrsreplaces MessageDialog(sselfsidstitles descriptionsselected_processorsxslTransformerIds content_types behave_likescachings debugLevelsREQUESTsRESPONSEsesurlsmessage((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysmanage_addXSLTMethods,      c Cs| p| otdn|i|t} | tjod|} t| n|i|t ||||||||| |i|idS(s Factory method to actually create an instance of XSLTMethod and return it. You should call this method directly if you are creating an instance of XSLTMethod programatically. s!Required fields must not be blanks&Invalid transformer name. %s not foundN(sidsxslTransformerIds ExceptionsselfsrestrictedTraversesNonestransmessages _setObjects XSLTMethodstitles descriptionsselected_processors content_types behave_likescachings debugLevels_getObsreindex_object( sselfsidstitles descriptionsselected_processorsxslTransformerIds content_types behave_likescachings debugLevelstransmessage((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys addXSLTMethods    s XSLTMethodc BstZdZdZeZeZhdd<dd<ddd?Z'eidd@Z(eidAdBZ)ei*e+dCeiedDei*edCeedEZ,eiedFeeedGZ-dHZ.eiedIdJZ/dKZ0RS(Ls Automatically transforms an XML document via XSLT, where both the XML document and XSLT are obtained from other Zope objects via acquisition. s XSLT Methodsidstitlestypesstringsmodesws descriptionstexts content_typesselected_processors selectionsselect_variablesavailableProcessorss debugLevelsintscachingsonOffslabelsEditsactionsmanage_editFormshelpsZopeXMLMethodssedit.stxs text/htmlssonic Cs||_||_||_||_||_||_||_||_| |_ t d||_ |i i |_|it jotdndS(Ns preferreds&No supported XSLT processors available(sidsselfstitles descriptionsselected_processorsxslTransformerIds content_types behave_likescachings debugLevelsProcessorChoosers_processorChoosersdefaultProcessorsNones Exception( sselfsidstitles descriptionsselected_processorsxslTransformerIds content_types behave_likescachings debugLevel((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys__init__s         s www/edit.pts manage_editcCsky|i|Wn4tj o(}tdddt|ddSnX||_d}|i d|SdS( s* Edit XSLTMethod settings stitlesErrorsmessagesactionsmanage_editFormsChanges saved.smanage_tabs_messageN( sselfs editTransformsxslTransformerIds Exceptionses MessageDialogsstrs behave_likesmessagesmanage_editForm(sselfsxslTransformerIds behave_likesREQUESTsRESPONSEsesmessage((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys manage_edits   smanage_editPropertiescCskxN|iD]@}|d}|djo#|i|d}|i|q q Wti d||SdS(s Cover for PropertyManager.manage_editProperties() method. set debugLevel of underlying XSLTProcessor to our debugLevel, then pass it on to the inherited method for further processing sids debugLevelssmanage_editPropertiesN( sselfs _propertyMapspropsnamesREQUESTsgetsvalues setDebugLevels XSLTMethodsinheritedAttribute(sselfsREQUESTsnamespropsvalue((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysmanage_editProperties&s   sisCacheFileUpToDatecCs|i}|tjodSn|i}|i}t|i i d}t|i i d}|i |id}||jo ||jSdS(ss Return 1 if and only if self should use the cached value rather than regenerating the transformed value, and the cache manager exists, and the cache file exists. Note: this algorithm is rather simple and limited right now, but we intend to improve it over time. Many items are not taken into account today: a) XML fragments that are included into the main document via the XSLT document() function b) XSLT transformer parameters c) XSLT transformers themselves (as well as all included and imported transformers). FIXME cks 11/26/2001 if0.5sURLN(sselfsfindCacheManagersmanagersNonesgetXmlSourceObjects srcObjectsgetXslTransformers xformObjectsroundsbobobase_modification_timestimeTimes sourceTimes xformTimescacheFileTimeStampsREQUESTsgets cacheTime(sselfsREQUESTs xformTimes sourceTimes srcObjects cacheTimesmanagers xformObject((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysisCacheFileUpToDate8s     sfindCacheManagercCst}|iSdS(sN Return names of currently available XSLT processor libraries N(sProcessorChoosers proc_choosers processors(sselfs proc_chooser((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysavailableProcessors_s s processorcCs|ii|iSdS(sN Obtain the object encapsulating the selected XSLT processor. N(sselfs_processorChoosersprocessorObjectsselected_processor(sself((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys processorgssxslTransformercCs|i|itSdS(sx Obtain the Zope object holding the XSLT, or None if the name does not point to a valid object. N(sselfsrestrictedTraversesxslTransformerIdsNone(sself((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysgetXslTransformernssgetXmlSourceObjectcCsRt|}x|iot|}qW|iodG|iGHn|SdS(sK Retrieve the source object by using acquisition on the ID sRequesting contents ofN(s aq_parentsselfsobsisPrincipiaFolderishs isDebuggingsgetId(sselfsob((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysgetXmlSourceObjectvs   s transformc Cs|i}|i}td||}|i}|i }td||}|i}|i |i|i||||||SdS(sM Generate result using transformer and return it as a string sXSL transformers XML sourceN(sselfs processorsgetXslTransformers xslObjectsgetPublishedResultsREQUESTs xslContentss absolute_urlsxslURLsgetXmlSourceObjects xmlObjects xmlContentssxmlURLs setDebugLevels debugLevels transform( sselfsREQUESTs xslObjects xmlContentss xslContentssxslURLsxmlURLs xmlObjects processor((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys transforms      s testTransformc Cs|i} |i}td||}|i}|i }td||}|i}| i |}| i|i| i|||||||SdS(s This version is used purely for testing. It is the same as transform() but it throws exceptions. This is used for negative tests. See tests/TestXSLTMethod() sXSL transformers XML sourceN(sselfs processorsgetXslTransformers xslObjectsgetPublishedResultsREQUESTs xslContentss absolute_urlsxslURLsgetXmlSourceObjects xmlObjects xmlContentssxmlURLsgetXSLParametersstopLevelParamss setDebugLevels debugLevels transformGuts( sselfsREQUESTs xslObjects xmlContentss xslContentsstopLevelParamssxslURLsxmlURLs xmlObjects processor((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys testTransforms"      s setCachingOncCs d|_dS(s\ same as changing the property. For use in scripts or by the cache Manager sonN(sselfscaching(sselfsREQUEST((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys setCachingOnss setCachingOffcCs d|_dS(s\ same as changing the property. For use in scripts or by the cache Manager soffN(sselfscaching(sselfsREQUEST((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys setCachingOffss isCachingOncCs|idjSdS(s5 Return true if caching is turned on sonN(sselfscaching(sself((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys isCachingOnss setDebugLevelcCs ||_dS(sL Set debug level for ourselves and our underlying processor N(svaluesselfs debugLevel(sselfsvalue((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys setDebugLevelss isDebuggingcCs|idjSdS(s= Return true if and only if debugging is on. iN(sselfs debugLevel(sself((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys isDebuggingss editTransformcCsF|i|t}|tjod|}t|n||_dS(sF Change transformer to be used or ID of source object sInvalid xslTransformerId %sN(sselfsrestrictedTraversesxslTransformerIdsNonestransmessages Exception(sselfsxslTransformerIdstransmessage((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys editTransforms   sgetSelfcCs|idSdS(s= Return this object. For use in DTML scripts iN(sselfsaq_chain(sself((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysgetSelfscCsddgSdS(Nsonsoff((sself((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysonOffssbehaveLikeListcCstiSdS(sV Return list of standard zope objects this XSLTMethod can behave like N(sGeneratorRegistryssupportedMetaTypes(sself((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysbehaveLikeListss Anonymouss index_htmlcCs||||SdS(s Default view of rendered version of XML Document. This is called when some one types the transformation path (e.g. "aSource/aXSLTMethod") directly into the browser, rather than via DTML or a page template. We *must* use this method to pass the REQUEST parameter on, otherwise we wouldn't get it because _render_with_namespace_ is *not* called in this case. N(sselfsREQUESTsRESPONSE(sselfsREQUESTsRESPONSE((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys index_html ss__call__c Cst}|ioM|i|o9|i}|tj o|i|i d}q\q`n|tjoV|i |}|i}|io |tj o|i |i d|qn|i djo|i i}n |i }ti|}|tjoti}n|tj o|id|in|i|i|i|d|i}|tjo |}n|i||||SdS(sV Render self by processing its content with the named XSLT stylesheet sURLss Content-Types content_typeN(sNones rawResultsselfs isCachingOnsisCacheFileUpToDatesREQUESTsfindCacheManagersmanagersvalueFromCachesgets transforms saveToCaches behave_likesgetXmlSourceObjects meta_typesGeneratorRegistrys getGeneratorsgensgetDefaultGeneratorsRESPONSEs setHeaders content_types createObjectsidstitlesobjsclients getResult( sselfsclientsREQUESTsRESPONSEsobjs behave_likesgensmanagers rawResult((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys__call__s2   $  !     is__render_with_namespace__cCs.|d}|d}|id|d|SdS(s Render with namespace namespace will be given to us by the ZPT that calls us, for example if a ZPT were to include something like the below:
replaceme
sREQUESTsRESPONSEN(s namespacesREQUESTsRESPONSEsselfs__call__(sselfs namespacesREQUESTsRESPONSE((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys__render_with_namespace__Os  cCsdS(s Repair this object. This method is used for schema migration, when the class definition changes and existing instances of previous versions must be updated. N((sself((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pysrepair_s(1s__name__s __module__s__doc__s meta_types IXSLTMethods__implements__sClassSecurityInfos _securitys _propertiessOFSsPropertyManagersmanage_optionss SimpleItems__init__sdeclareProtecteds PERM_MANAGEsPageTemplateFilesglobalssmanage_editForms PERM_EDITsNones manage_editsmanage_editPropertiess PERM_VIEWsisCacheFileUpToDatesfindCacheManagers declarePublicsavailableProcessorss processorsgetXslTransformersgetXmlSourceObjects transforms testTransforms setCachingOns setCachingOffs isCachingOns setDebugLevels isDebuggings editTransformsgetSelfsonOffsbehaveLikeListssetPermissionDefaults PERM_CONTENTs index_htmls__call__s isDocTemps__render_with_namespace__srepair(((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys XSLTMethodsr   D  #                         3 ()s__doc__s __cvstag__s__date__s __version__s mimetypessOFS.SimpleItems SimpleItems"Products.ZCatalog.CatalogAwarenesss CatalogAwaresOFS.PropertyManagersPropertyManagers IXSLTMethodsProcessorChoosersGeneratorRegistrysOFSsGlobalss MessageDialogs Acquisitionsaq_bases aq_parents AccessControlsClassSecurityInfosZPublisher.mapplysmapplys'Products.PageTemplates.PageTemplateFilesPageTemplateFiles PERM_VIEWs PERM_EDITsPERM_FTPs PERM_CONTENTs PERM_MANAGEsgetPublishedResultsfindCacheManagers addInstancesglobalssmanage_addXSLTMethodFormsNonesmanage_addXSLTMethods addXSLTMethods XSLTMethodsInitializeClass(s IXSLTMethodsmapplys aq_parentsgetPublishedResults PERM_EDITs __cvstag__s PERM_MANAGEsPERM_FTPs PERM_CONTENTsGeneratorRegistrysPageTemplateFiles __version__s addXSLTMethods mimetypessClassSecurityInfosaq_bases PERM_VIEWs XSLTMethodsOFSsmanage_addXSLTMethodForms MessageDialogs SimpleItems CatalogAwares addInstancesProcessorChoosers__date__sfindCacheManagersGlobalssPropertyManagersmanage_addXSLTMethod((sH/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/XSLTMethod.pys?s>                  2!'%!