Ńň
MŘqKc           @   s  d  Z  d d d !Z d d d !Z d d d !Z d d k l Z d d	 k l Z d d
 k l	 Z	 d d k
 l
 Z
 d d k l Z l Z l Z l Z l Z l Z l Z d d k Z d d k l Z d d k l Z d d k l Z d d k l Z d Z d d d d d d d d  Z e d e    Z d d d d d d d d d d 	 Z d d d d d d d d  Z  d   Z! d e f d     YZ" e i# e"  d S(   sĚ  
$RCSfile: XPathMethod.py,v $

ZopeXMLMethods provides methods to apply to Zope objects for XML/XSLT
processing.  XPathMethod applies XPath expressions to XML documents.
XPathMethod automatically filters an XML document via XPath, where the
XML document is obtained from another Zope object (the 'source'
object) via acquisition.

Author: Craeg Strong <cstrong@arielpartners.com>
Release: 1.0

$Id: XPathMethod.py,v 1.2 2003/06/16 05:47:53 arielpartners Exp $
s	   $Name:  $i   iţ˙˙˙s   $Date: 2003/06/16 05:47:53 $s   $Revision: 1.2 $i
   i˙˙˙˙(   t   IXPathMethod(   t   IXPathProcessor(   t   ProcessorRegistry(   t   GeneratorRegistry(   t	   XMLMethodt   getPublishedResultt	   PERM_VIEWt	   PERM_EDITt   PERM_FTPt   PERM_CONTENTt   PERM_MANAGEN(   t   MessageDialog(   t   ClassSecurityInfo(   t   PageTemplateFile(   t
   implementst   XPathexpressiont    s   text/xmli    c	   	   	   C   s1   |  i  d i | | | | | | | |  |  | S(   sý   
    This is a convenience factory method for creating an instance of
    XPathMethod.  It returns the object created, and may therefore be
    more convenient than the addXPathMethod() method it calls.  It is
    used by the unit testing programs.
    t   ZopeXMLMethods(   t   manage_addProductt   addXPathMethod(	   t   foldert   idt   titlet   descriptiont   selected_processort   xpathExpressiont   content_typet   behave_liket
   debugLevel(    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyt   addInstance.   s    
s   www/createXPath.ptc         C   sĚ   y~ |  i  | | | | | | | |  d | d } |	 d j o d Sy |  i   } Wn |	 d } n X|	 i i | d  WnG t j
 o; } t |  } | i d d  t d d	 d
 | d d  SXd S(   sŹ   
    Factory method to create an instance of XPathMethod, called from
    a GUI in the Zope Management Interface.  It calls addXPathMethod
    to actually do the work.
    s   Successfully created s    XPathMethod object.Nt   URL1s   /manage_mains   
s   <br/>R   t   Errort   messaget   actiont   manage_main(	   R   t   Nonet   DestinationURLt   RESPONSEt   redirectt	   Exceptiont   strt   replaceR   (   t   selfR   R   R   R   R   R   R   R   t   REQUESTR%   R    t   urlt   e(    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyt   manage_addXPathMethodB   s$    

c	   	      C   sb   | p | o t  d   n |  i | t | | | | | | | |   |  i |  i   d S(   sÇ   
    Factory method to actually create an instance of XPathMethod and
    return it.

    You should call this method directly if you are creating an
    instance of XPathMethod programatically.
    s!   Required fields must not be blankN(   R'   t
   _setObjectt   XPathMethodt   _getObt   reindex_object(	   R*   R   R   R   R   R   R   R   R   (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyR   b   s    c         C   s   t  i t  S(   sG   
    Return names of currently available XPath processor libraries
    (   R   t   namesR   (   R*   (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyt   availableProcessorsz   s    R0   c           B   sç   e  Z d  Z d Z e e  e   Z e i	 h d d 6d d 6d d 6f Z	 d d	 d
 d  Z
 e i d  d   Z e i d  d   Z e i e d  d   Z e i e d  d   Z e i e d  d d d d  Z d   Z RS(   sĽ   
    Automatically filters an XML document via XPath, where the XML
    document is obtained from another Zope object (the 'source'
    object) via acquisition.
    s   XPath MethodR   R   t   stringt   typet   wt   modes	   text/htmlR   i    c	   	   	   C   sO   t  i |  | | | | | | |  | |  _ |  i p t i t  |  _ n d  S(   N(   R   t   __init__R   R   R   t   defaultNameR   (	   R*   R   R   R   R   R   R   R   R   (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyR9      s    
	
R4   c         C   s   t  i t  S(   sO   
        Return names of currently available XPath processor libraries
        (   R   R3   R   (   R*   (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyR4   Ź   s    t	   processorc         C   s   t  i t |  i  S(   sO   
        Obtain the object encapsulating the selected XPath processor.
        (   R   t   itemR   R   (   R*   (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyR;   ł   s    	t   evaluateStringc         C   sn   |  i    } |  i   } t d | |  } | i   } | i |  i  | i |  i  } | i | | d d S(   sh   
        Generate result of applying XPath against source XML and
        return it as a string
        s
   XML sourcet   prettyPrinti   (	   R;   t   getXmlSourceObjectR   t   absolute_urlt   setDebugLevelR   t   compileR   R=   (   R*   R+   R;   t	   xmlObjectt   xmlContentst   xmlURLt   expr(    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyR=   ť   s    t   evaluateDOMc         C   sh   |  i    } |  i   } t d | |  } | i   } | i |  i  | i |  i  } | i | |  S(   ss   
        Generate result of applying XPath against source XML and
        return it as a list of DOM nodes
        s
   XML source(	   R;   R?   R   R@   RA   R   RB   R   RG   (   R*   R+   R;   RC   RD   RE   RF   (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyRG   Ď   s    t   __call__c         C   sÜ   |  i  |  } |  i d j o |  i   i } n
 |  i } t i |  } | d j o t i   } n | d j	 o | i d |  i	  n | i
 |  i |  i | d |  i	 } | d j o
 |  } n | i | | | |  S(   sL   
        Render self by processing its content with the named XPath
        R   s   Content-TypeR   N(   R=   R   R?   t	   meta_typeR   t   getGeneratorR#   t   getDefaultGeneratort	   setHeaderR   t   createObjectR   R   t	   getResult(   R*   t   clientR+   R%   t	   rawResultR   t   gent   obj(    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyRH   ç   s    	
c         C   s   d S(   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(    (   R*   (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyt   repair	  s    N(   t   __name__t
   __module__t   __doc__RI   R   R    R   t	   _securityR   t   _propertiesR9   t   declarePublicR4   R;   t   declareProtectedR   R=   RG   R#   RH   RS   (    (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyR0      s&   
					"($   RV   t
   __cvstag__t   __date__t   __version__t
   interfacesR    t   processors.interfacesR   t   processors.ProcessorRegistryR   R   R   R   R   R   R   R	   R
   t   GlobalsR   t   AccessControlR   t'   Products.PageTemplates.PageTemplateFileR   t   zope.interfaceR   t   xpathExpressionPropertyNameR   t   globalst   manage_addXPathMethodFormR#   R.   R   R4   R0   t   InitializeClass(    (    (    s0   /srv/Zope/Products/ZopeXMLMethods/XPathMethod.pyt   <module>   s:   4		