Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes
xml.XsltTransform Class Reference
Inheritance diagram for xml.XsltTransform:
Inheritance graph
[legend]
Collaboration diagram for xml.XsltTransform:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __getattr__
def convert
def invokeCommand

Public Attributes

 config
 config_metadata

Private Attributes

 __name__

Static Private Attributes

tuple __implements__ = (itransform,)
string __name__ = "xml_to_html"

Detailed Description

Custom external command

transform xml content by launching an external XSLT processor

Input and output mime types must be set correctly !

You can associate different document type to different transformations.

Definition at line 17 of file xml.py.


Constructor & Destructor Documentation

def xml.XsltTransform.__init__ (   self,
  name = None,
  kwargs 
)

Definition at line 30 of file xml.py.

00030 
00031     def __init__(self, name=None, **kwargs):
00032         self.config = {
00033             # sample configuration
00034             'binary_path'  : bin_search('xsltproc'),
00035             'command_line' : '%(transform)s %(input)s',
00036             'inputs'       : ('text/xml',),
00037             'output'       : 'text/html',
00038             'output_encoding' : 'UTF-8',
00039             'dtds'         : {
00040             '-//OASIS//DTD DocBook V4.1//EN' : '/usr/share/sgml/docbook/xsl-stylesheets-1.29/html/docbook.xsl'
00041             },
00042             'default_transform': ''
00043             }
00044         self.config_metadata = {
00045             'binary_path'  : ('string', 'Binary path',
00046                               'Path of the executable on the server.'),
00047             'command_line' : ('string', 'Command line',
00048                               '''Additional command line option.
00049 There should be at least the input file (designed by "%(input)s") and the xsl
00050 file (designed by "%(transform)s").The transformation\'s result must be printed on stdout.
00051 '''),
00052             'inputs'       : ('list', 'Inputs', 'Input(s) MIME type. Change with care.'),
00053             'output'       : ('string', 'Output', 'Output MIME type. Change with care.'),
00054             'output_encoding': ('string', 'Output encoding', 'Output encoding.'),
00055             'dtds'         : ('dict', 'DTDs',
00056                               'Association of public ids or dtds to XSL transformations.',
00057                               ('Public id', 'XSLT path')),
00058             'default_transform' : ('string', 'Default xslt',
00059                                    'Default xslt, used when no specific transformation is found.'),
00060             }
00061         self.config.update(kwargs)
00062         if name:
00063             self.__name__ = name


Member Function Documentation

def xml.XsltTransform.__getattr__ (   self,
  attr 
)

Definition at line 64 of file xml.py.

00064 
00065     def __getattr__(self, attr):
00066         if attr == 'inputs':
00067             return self.config['inputs']
00068         if attr == 'output':
00069             return self.config['output']
00070         if attr == 'output_encoding':
00071             return self.config['output_encoding']
00072         raise AttributeError(attr)
00073 

Here is the caller graph for this function:

def xml.XsltTransform.convert (   self,
  data,
  cache,
  kwargs 
)

Definition at line 74 of file xml.py.

00074 
00075     def convert(self, data, cache, **kwargs):
00076         base_name = sansext(kwargs.get("filename") or 'unknown.xml')
00077         dtds = self.config['dtds']
00078         tmpdir, fullname = self.initialize_tmpdir(data, filename=base_name)
00079         try:
00080             try:
00081                 doctype = get_doctype(data)
00082             except DTException:
00083                 try:
00084                     doctype = get_dtd(data)
00085                 except DTException:
00086                     log('Unable to get doctype nor dtd in %s' % data)
00087                     doctype = None
00088             if doctype and dtds.has_key(doctype):
00089                 data = self.invokeCommand(fullname, dtds[doctype])
00090             elif self.config['default_transform']:
00091                 data = self.invokeCommand(fullname, self.config['default_transform'])
00092             cache.setData(data)
00093             path, images = self.subObjects(tmpdir)
00094             objects = {}
00095             if images:
00096                 self.fixImages(path, images, objects)
00097                 cache.setSubObjects(objects)
00098             return cache
00099         finally:
00100             self.cleanDir(tmpdir)
00101 

Here is the call graph for this function:

def xml.XsltTransform.invokeCommand (   self,
  input_name,
  xsl 
)

Definition at line 102 of file xml.py.

00102 
00103     def invokeCommand(self, input_name, xsl):
00104         dest_dir = dirname(input_name)
00105         output_file = join(dirname(input_name), 'tr_output')
00106         command = '%(binary_path)s %(command_line)s' % self.config
00107         data = {'input': input_name, 'output': output_file, 'transform': xsl}
00108         system(command % data)
00109 
00110         if exists(output_file):
00111             data = open(output_file).read()
00112         else:
00113             data = 'error occurs during transform. See error log'
00114         return data
00115 
00116 

Here is the caller graph for this function:


Member Data Documentation

tuple xml.XsltTransform.__implements__ = (itransform,) [static, private]

Definition at line 26 of file xml.py.

string xml.XsltTransform.__name__ = "xml_to_html" [static, private]

Definition at line 28 of file xml.py.

Definition at line 62 of file xml.py.

Definition at line 31 of file xml.py.

Definition at line 43 of file xml.py.


The documentation for this class was generated from the following file: