[Bio] / WebApplication / WikiShim.pm Repository:
ViewVC logotype

View of /WebApplication/WikiShim.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.6 - (download) (as text) (annotate)
Wed Apr 22 23:23:31 2009 UTC (10 years, 7 months ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, mgrast_dev_03052011, mobedac_release_05302012, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2009_07_09, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.5: +4 -1 lines
Fixed to fully specify the web-app-backend connection data.

#!/usr/bin/perl -w

# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
# This file is part of the SEED Toolkit.
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License.
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.

package WikiShim;

    use strict;
    use Tracer;
    use CGI;
    use HTML::Template;
    use DBMaster;
    use WebMenu;
    use WebLayout;
    use TWiki::Func;
    use base qw(WebApplication);

=head1 WikiShim Package

Wiki / WebApplication shim

=head2 Introduction

This object embeds a WebApplication page in the wiki. A special template is used
that generates only the interior portion of the HTML. The output from the web
-application page is harvested from the application object and then embedded in
a wiki page.

The object is always called from a REST invocation, so we have access to the
wiki functions. The wiki page is assembled in a normal manner and the
web-application output replaces the text variable.

The fields in this object are as follows.

=over 4

=item cgi

CGI query object used to generate output and access parameters

=item session

TWiki session object

=item application

WebApplication object for this application



=head3 new

    my $wshim = WikiShim->new(%options);

Construct a new WikiShim object. The following options are supported.

=over 4

=item cgi

CGI object containing the query parameters. If none is provided, one will be created.
This is generally a bad thing, however.

=item application

Name of the web application



sub new {
    # Get the parameters.
    my ($class, %options) = @_;
    # Get the options.
    my $cgi = $options{cgi} || CGI->new();
    my $applicationID = $options{application} || 'SeedViewer';
    my $defaultPage = $options{default} || 'Home';
    Trace("Wiki shim for $applicationID.") if T(3);
    # Compute the application label. This is "GenomeViewer" for the SEED viewer and is
    # otherwise unaltered.
    my $appName = ($applicationID eq 'SeedViewer' ? 'GenomeViewer' : $applicationID);
    # Create a menu. We don't use the menus, but we don't want WebApplication
    # to fail if the page has custom menus to add.
    my $menu = WebMenu->new();
    # Create the layout object. To do this, we ask the wiki to build a template string for us.
    my $template = TWiki::Func::loadTemplate('view');
    # Get rid of the unneeded meta-variable values.
    $template =~ s/%REVTITLE%//g;
    Trace("Template string is:\n$template") if T(3);
    # Expand it.
    my $raw = TWiki::Func::expandCommonVariables($template, $appName, 'Main');
    # Render it into HTML.
    my $html = TWiki::Func::renderText($raw, 'Main');
    # Clean the nops.
    $html =~ s/<nop>//g;
    # Now we have raw HTML in $html that has the variable "%TEXT%" where the page text is supposed to go.
    # Our first task is to sneak the frame template variables into the header. First, the page title.
    $html =~ s#<title>(.+)</title>#<title><TMPL_VAR NAME="TITLE"></title>#;
    # Next, the style/java/meta stuff.
    my $frameTemplateText = <<____END;
        <link rel="stylesheet" type="text/css" href="<TMPL_VAR NAME="CSSFILE">" >
        <script type="text/javascript" src="<TMPL_VAR NAME="JSFILE">" ></script>
    $html =~ s#<!-- WebApplicationHeaders -->#$frameTemplateText</head>#;
    # This next trick connects the frame template to the body template.
    $html =~ s/%TEXT%/<TMPL_VAR NAME="BODY">/;
    # We have our frame template. Now we need the body template.
    my $bodyTemplateText = <<____END;
     <div id="warning">
        <p class="warning"> <strong> Warning: </strong> <TMPL_VAR NAME="MSG"> </p>
     <div id="info">
        <p class="info"> <strong> Info: </strong> <TMPL_VAR NAME="MSG"> </p>
     <div id="content">
    # The two templates enable us to create a layout object.
    my $layout = WebLayout->new({ frame => $html, body => $bodyTemplateText });
    # Tell the layout object we need to fix up links.
    # Create the web-application object. We set noTrace because tracing is already
    # turned on, and we pass the CGI object so that the correct parameters are
    # available.
    my $retVal = WebApplication::new($class,
                                      { id       => $applicationID,
                                        cgi      => $cgi,
                                        noTrace  => 1,
                                        dbmaster => DBMaster->new(-database => $FIG_Config::webapplication_db,
                                                                  -host     => $FIG_Config::webapplication_host,
                                                                  -user     => $FIG_Config::webapplication_user,
                                                                  -password => $FIG_Config::webapplication_password),
                                        menu     =>  $menu,
                                        layout   =>  $layout,
                                        default  => $defaultPage,
                                      } );
    # Denote we're the NMPDR.
    $retVal->page_title_prefix("$appName ");
    # Return the object.
    return $retVal;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3