Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
MoinMoin.parser.text_xslt.Parser Class Reference

List of all members.

Public Member Functions

def __init__
def format
def append_stylesheet
def parse_result

Public Attributes

 raw
 request
 form
 base_scheme
 base_uri
 key
 processor

Static Public Attributes

int caching = 1
 Dependencies = Dependencies

Private Member Functions

def _resolve_page

Private Attributes

 _

Detailed Description

Send XML file formatted via XSLT. 

Definition at line 25 of file text_xslt.py.


Constructor & Destructor Documentation

def MoinMoin.parser.text_xslt.Parser.__init__ (   self,
  raw,
  request,
  kw 
)

Definition at line 30 of file text_xslt.py.

00030 
00031     def __init__(self, raw, request, **kw):
00032         self.raw = raw
00033         self.request = request
00034         self.form = request.form
00035         self._ = request.getText
00036         self.base_scheme = 'wiki'
00037         self.base_uri = 'wiki://Self/'
00038         self.key = 'xslt'

Here is the caller graph for this function:


Member Function Documentation

def MoinMoin.parser.text_xslt.Parser._resolve_page (   self,
  uri,
  base 
) [private]
URI will be resolved into StringIO with actual page content 

Definition at line 122 of file text_xslt.py.

00122 
00123     def _resolve_page(self, uri, base):
00124         """ URI will be resolved into StringIO with actual page content """
00125         from Ft.Lib import Uri
00126         base_uri = self.base_uri
00127 
00128         if uri.startswith(base_uri):
00129             pagename = uri[len(base_uri):]
00130             page = Page.Page(self.request, pagename)
00131             if page.exists():
00132                 result = StringIO.StringIO(page.getPageText().encode(config.charset))
00133             else:
00134                 raise Uri.UriException(Uri.UriException.RESOURCE_ERROR, loc=uri,
00135                                        msg='Page does not exist')
00136         else:
00137             result = Uri.UriResolverBase.resolve(self, uri, base)
00138 
00139         return result

Here is the caller graph for this function:

for other parsers based on xslt (i.e. docbook-xml) 

Definition at line 140 of file text_xslt.py.

00140 
00141     def append_stylesheet(self):
00142         """ for other parsers based on xslt (i.e. docbook-xml) """
00143         pass

def MoinMoin.parser.text_xslt.Parser.format (   self,
  formatter 
)
Send the text. 

Definition at line 39 of file text_xslt.py.

00039 
00040     def format(self, formatter):
00041         """ Send the text. """
00042         _ = self._
00043 
00044         if not self.request.cfg.allow_xslt:
00045             # use plain text parser if XSLT is not allowed
00046             # can be activated in wikiconfig.py
00047             from MoinMoin.parser.text import Parser as TextParser
00048             self.request.write(formatter.sysmsg(1) +
00049                                formatter.rawHTML(_('XSLT option disabled, please look at HelpOnConfiguration.', wiki=True)) +
00050                                formatter.sysmsg(0))
00051             TextParser(self.raw, self.request).format(formatter)
00052             return
00053 
00054         try:
00055             # try importing Ft from 4suite
00056             # if import fails or its version is not 1.x, error msg
00057             from Ft.Xml import __version__ as ft_version
00058             assert ft_version.startswith('1.')
00059         except (ImportError, AssertionError):
00060             self.request.write(self.request.formatter.sysmsg(1) +
00061                                self.request.formatter.text(_('XSLT processing is not available, please install 4suite 1.x.')) +
00062                                self.request.formatter.sysmsg(0))
00063         else:
00064             from Ft.Lib import Uri
00065             from Ft.Xml import InputSource
00066             from Ft.Xml.Xslt.Processor import Processor
00067             from Ft import FtException
00068 
00069             msg = None
00070 
00071             try:
00072                 # location of SchemeRegisteryResolver has changed since 1.0a4
00073                 if ft_version >= "1.0a4" or ft_version == "1.0" or ("1.0.1" <= ft_version <= "1.0.9"):
00074                     # such version numbers suck!
00075                     import Ft.Lib.Resolvers # Do not remove! it looks unused, but breaks when removed!!!
00076 
00077                 class MoinResolver(Uri.SchemeRegistryResolver):
00078                     """ supports resolving self.base_uri for actual pages in MoinMoin """
00079                     def __init__(self, handlers, base_scheme):
00080                         Uri.SchemeRegistryResolver.__init__(self, handlers)
00081                         self.supportedSchemes.append(base_scheme)
00082 
00083                 # setting up vars for xslt Processor
00084                 out_file = StringIO.StringIO()
00085                 wiki_resolver = MoinResolver(
00086                                     handlers={self.base_scheme: self._resolve_page, },
00087                                     base_scheme=self.base_scheme)
00088                 input_factory = InputSource.InputSourceFactory(resolver=wiki_resolver)
00089 
00090                 page_uri = self.base_uri + wikiutil.url_quote(formatter.page.page_name)
00091                 # 4Suite needs an utf-8 encoded byte string instead of an unicode object
00092                 raw = self.raw.strip().encode('utf-8')
00093                 self.processor = Processor()
00094                 self.append_stylesheet() # hook, for extending this parser
00095                 self.processor.run(
00096                     input_factory.fromString(raw, uri=page_uri),
00097                     outputStream=out_file)
00098                 # Convert utf-8 encoded byte string into unicode
00099                 result = out_file.getvalue().decode('utf-8')
00100                 result = self.parse_result(result) # hook, for extending this parser
00101 
00102             except FtException, msg:
00103                 etype = "XSLT"
00104             except Uri.UriException, msg:
00105                 etype = "XSLT"
00106             except IOError, msg:
00107                 etype = "I/O"
00108 
00109             if msg:
00110                 text = wikiutil.escape(self.raw)
00111                 text = text.expandtabs()
00112                 text = text.replace('\n', '<br>\n')
00113                 text = text.replace(' ', '&nbsp;')
00114                 before = _('%(errortype)s processing error') % {'errortype': etype, }
00115                 title = u"<strong>%s: %s</strong><p>" % (before, msg)
00116                 self.request.write(title)
00117                 self.request.write(text.decode(config.charset))
00118             else:
00119                 self.request.write(result)
00120                 cache = caching.CacheEntry(self.request, formatter.page, self.key, scope='item')
00121                 cache.update(result)

Here is the call graph for this function:

def MoinMoin.parser.text_xslt.Parser.parse_result (   self,
  result 
)
additional parsing to the resulting XSLT'ed result before saving 

Definition at line 144 of file text_xslt.py.

00144 
00145     def parse_result(self, result):
00146         """ additional parsing to the resulting XSLT'ed result before saving """
00147         return result
00148 

Member Data Documentation

Definition at line 34 of file text_xslt.py.

Definition at line 35 of file text_xslt.py.

Definition at line 36 of file text_xslt.py.

Definition at line 27 of file text_xslt.py.

Definition at line 28 of file text_xslt.py.

Definition at line 33 of file text_xslt.py.

Definition at line 37 of file text_xslt.py.

Definition at line 92 of file text_xslt.py.

Definition at line 31 of file text_xslt.py.

Definition at line 32 of file text_xslt.py.


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