コード例 #1
0
def render(self, source_xml, content_type):
    """Render document using 4suite.

    """
    #pubUrl = self.REQUEST['PUBLISHED'].absolute_url()
    pubUrl = self.REQUEST['URL']
    proc = Processor.Processor()
    resolver = ZBaseUriResolver(self)

    factory = InputSource.InputSourceFactory(resolver=resolver)
    source = factory.fromString(self().encode(self.char_encoding), '/'.join(self.getPhysicalPath()))
    proc.appendStylesheet(source)


    if content_type in ['text/xml','text/html']:
        writer = XmlWriter.XmlWriter(proc.outputParams,StringIO.StringIO())
    else:
        writer = StringWriter.StringWriter(proc.outputParams,
                                           StringIO.StringIO())

    # Apply the stylesheet to the XMLTemplate. The result is
    # written to the output stream attribute of the writer so
    # grab that and send it back to the caller.
    proc.run(factory.fromString(source_xml),pubUrl,writer=writer)

    return writer.getStream().getvalue()
コード例 #2
0
    def get_factory(self):
        system_catalogs = ['/etc/xml/catalog', '/usr/local/share/xml/catalog']

        system_catalogs = [p for p in system_catalogs if os.path.exists(p)]

        if system_catalogs:
            xml_catalog_files = os.getenv("XML_CATALOG_FILES")
            if xml_catalog_files:
                xml_catalog_files += " " + " ".join(system_catalogs)
            else:
                xml_catalog_files = " ".join(system_catalogs)
            os.environ["XML_CATALOG_FILES"] = xml_catalog_files

        # The factory now takes into account the new XSML_CATALOG_FILES
        factory = InputSource.InputSourceFactory(
            catalog=Catalog.GetDefaultCatalog())
        return factory
コード例 #3
0
ファイル: text_xslt.py プロジェクト: aahlad/soar
    def format(self, formatter):
        """ Send the text. """
        _ = self._

        if not self.request.cfg.allow_xslt:
            # use plain text parser if XSLT is not allowed
            # can be activated in wikiconfig.py
            from MoinMoin.parser.text import Parser as TextParser
            self.request.write(
                formatter.sysmsg(1) + formatter.rawHTML(
                    _('XSLT option disabled, please look at HelpOnConfiguration.',
                      wiki=True)) + formatter.sysmsg(0))
            TextParser(self.raw, self.request).format(formatter)
            return

        try:
            # try importing Ft from 4suite
            # if import fails or its version is not 1.x, error msg
            from Ft.Xml import __version__ as ft_version
            assert ft_version.startswith('1.')
        except (ImportError, AssertionError):
            self.request.write(
                self.request.formatter.sysmsg(1) + self.request.formatter.text(
                    _('XSLT processing is not available, please install 4suite 1.x.'
                      )) + self.request.formatter.sysmsg(0))
        else:
            from Ft.Lib import Uri
            from Ft.Xml import InputSource
            from Ft.Xml.Xslt.Processor import Processor
            from Ft import FtException

            msg = None

            try:
                # location of SchemeRegisteryResolver has changed since 1.0a4
                if ft_version >= "1.0a4" or ft_version == "1.0" or (
                        "1.0.1" <= ft_version <= "1.0.9"):
                    # such version numbers suck!
                    import Ft.Lib.Resolvers  # Do not remove! it looks unused, but breaks when removed!!!

                class MoinResolver(Uri.SchemeRegistryResolver):
                    """ supports resolving self.base_uri for actual pages in MoinMoin """
                    def __init__(self, handlers, base_scheme):
                        Uri.SchemeRegistryResolver.__init__(self, handlers)
                        self.supportedSchemes.append(base_scheme)

                # setting up vars for xslt Processor
                out_file = StringIO.StringIO()
                wiki_resolver = MoinResolver(handlers={
                    self.base_scheme:
                    self._resolve_page,
                },
                                             base_scheme=self.base_scheme)
                input_factory = InputSource.InputSourceFactory(
                    resolver=wiki_resolver)

                page_uri = self.base_uri + wikiutil.url_quote(
                    formatter.page.page_name)
                # 4Suite needs an utf-8 encoded byte string instead of an unicode object
                raw = self.raw.strip().encode('utf-8')
                self.processor = Processor()
                self.append_stylesheet()  # hook, for extending this parser
                self.processor.run(input_factory.fromString(raw, uri=page_uri),
                                   outputStream=out_file)
                # Convert utf-8 encoded byte string into unicode
                result = out_file.getvalue().decode('utf-8')
                result = self.parse_result(
                    result)  # hook, for extending this parser

            except FtException, msg:
                etype = "XSLT"
            except Uri.UriException, msg:
                etype = "XSLT"
コード例 #4
0
def GetMappingFactory(uriMapping):
    return InputSource.InputSourceFactory(resolver=MappingResolver(uriMapping))
コード例 #5
0
    BASE_URI + 'STY2': style2,
    BASE_URI + 'STY3': style3,
    BASE_URI + 'STY4': style4,
}


class GenericInputSource(InputSource.InputSource):
    def _openStream(self, uri, ignoreErrors=False, hint=None):
        scheme = urlparse.urlparse(uri)[0]
        #if scheme in ['', 'http', 'ftp', 'file', 'gopher']:
        #    raise uri
        st = URIS[uri]
        return cStringIO.StringIO(st)


InputSourceFactory = InputSource.InputSourceFactory(GenericInputSource)

DOC1_STY1_EXPECTED = """<?xml version="1.0" encoding="UTF-8"?>
STY1DOC1"""

DOC1_STY2_EXPECTED = """<?xml version="1.0" encoding="UTF-8"?>
STY2DOC1"""

DOC1_STY3_EXPECTED = """<?xml version="1.0" encoding="UTF-8"?>
STY3DOC1"""

DOC1_STY4_EXPECTED = """<?xml version="1.0" encoding="UTF-8"?>
STY4DOC2"""


def Test(tester):