Ambrosia

 view release on metacpan or  search on metacpan

Example/README  view on Meta::CPAN


Also you must have the installed dojotoolkit version 1.7.2, you can download it
from http://download.dojotoolkit.org/release-1.7.2/dojo-release-1.7.2.tar.gz

Run PATH_TO_SCRIPT/ambrosia and answer some questions.

For example:

Enter the name of project: Music
Enter the title of project [Music]:The Music Catalogue
Enter the charset of project for output results [utf-8]:
Enter the path for root directory of project [/home/Ambrosia/Project/Example]:
Enter the domain for web server [my.domain]:ambrosia.domain
Enter the port for web server [8042]:
Enter the path for perl's lib [empty for done]: /home/Ambrosia/myperllib/CPAN/perl5lib/lib/perl5
Enter the path for perl's lib [empty for done]: /home/Ambrosia/myperllib/CPAN/perl5lib/lib/perl5/i386-freebsd-64int
Enter the path for perl's lib [empty for done]: /home/Ambrosia/Project/lib
Enter the path for perl's lib [empty for done]:
Enter the path to dojo toolkit:/home/Ambrosia/DOJO/dojo-release-1.7.2
Choose the database [m(MySQL)|p(PostgresQL)]: m
Enter the schema of database [Music]:MusicDB
Enter the host location of database [localhost]:
Enter the port for connection to database or enter 's' for use UNIX socket [3306]:
Enter the username of database [root]:
Enter user's password []:
Enter the charset of database [utf8]:
Enter the settings for connecting to the database as a string [database=MusicDB;host=localhost;port=3306]:

Then follow the instructions.

For access to created application you must use 
    login => 'god',
    password => 'fv,hjpbz'

You can change it in the PATH_TO_PROJECT/Music/Config/Music.conf

lib/Ambrosia/CommonGatewayInterface/ApacheRequest.pm  view on Meta::CPAN


################################################################################

sub crlf() { "\r\n"; }

sub prepare_header
{
    my %params = @_;
    my @headers = ();
    my $type = 'Content-Type: text/html';
    my $charset = '';
    my $date;
    my $nph;
    my $status;
    my $no_cache;

    foreach ( keys %params )
    {
        /-?([[:alnum:]]+)(?:[-_](\w+))?/;
        my $k = uc($1 . ($2 ? ('-' . $2) : ''));

        if ( $k eq 'TYPE' || $k eq 'CONTENT-TYPE')
        {
            $type = 'Content-Type: ' . $params{$_};
        }
        elsif( $k eq 'CHARSET' )
        {
            $charset = $params{$_};
        }
        elsif( $k eq 'PRAGMA')
        {
            $no_cache = $params{$_};
        }
        elsif( $k eq 'COOKIE' || $k eq 'COOKIES' )
        {
            my @cookies = ref $params{$_} eq 'ARRAY' ? @{$params{$_}} : $params{$_};
            foreach (@cookies)
            {

lib/Ambrosia/CommonGatewayInterface/ApacheRequest.pm  view on Meta::CPAN

            /-?([[:alnum:]]+)(?:[-_](\w+))?/;
            push @headers, ($1 . ($2 ? ('-' . $2) :'')) . ': ' . $params{$_};
        }
    }

    if ( defined $nph )
    {
        $nph .= ($status || '200 OK') . 'Server: ' . $ENV{SERVER_SOFTWARE};
    }

    if ($charset && $type !~ /\bcharset\b/)
    {
        $type .= '; charset=' . $charset;
    }

    push @headers, $type;

    if ( $date )
    {
        push @headers, 'Date: ' . expires(0, 'http');
    }

    return ($nph, $no_cache, \@headers);    

lib/Ambrosia/Utils/Util.pm  view on Meta::CPAN

        s/&/&/sg;
        s/</&lt;/sg;
        s/>/&gt;/sg;
        s/"/&quot;/sg;
        return $_;
    }
}

sub unescape_html
{
    #my $latin = defined $self->{'.charset'}
    #            ? $self->{'.charset'} =~ /^(ISO-8859-1|WINDOWS-125[12]|KOI8-?R)$/i
    #            : 1;
    for ( shift )
    {
        s/&amp;/&/sg;
        s/&lt;/</sg;
        s/&gt;/>/sg;
        s/&quot;/"/sg;
        s/&nbsp;/ /sg;
        if ( @_ )
        {

lib/Ambrosia/View.pm  view on Meta::CPAN

package Ambrosia::View;
use strict;
use warnings;

use Ambrosia::Meta;

class abstract
{
    public => [qw/charset template data/],
};

our $VERSION = 0.010;

sub render
{
    my $self = shift;
    $self->template = shift;
    $self->data = shift;
    return $self->process;

lib/Ambrosia/View/XSLT.pm  view on Meta::CPAN

#use Data::Dumper;
sub __as_xml
{
    my $self = shift;
    my $ignore = shift;
    my $name_node = shift;

    my ($document, $node);
    eval
    {
        my $charset = $self->charset || 'utf-8';
        $document = XML::LibXML->createDocument( '1.0', $charset );

        $node = $document->createElement($name_node || 'context');

        my $data = $self->data;

        foreach my $p ( keys %$data )
        {
            next if $p eq 'query';

            my $value = $data->{$p};

lib/Ambrosia/core/Object.pm  view on Meta::CPAN

    }
    else
    {
        $ex_node->setAttribute( $p, $v );
    }
    return $ex_node;
}

# Parameters
#    document => 'xml_document', #optional. If not defined then the document will be created.
#    charset => 'charset_of_xml_document', #if not defined document. Optional. Default is 'utf8'
#    name => 'name_of_root_node', #optional. If nod present then the name will be making from '$self'
#    error_ignore => 'true or false in perl notation (1 or 0))', #optional. default is true
#    methods => [], #optional. See 
#

sub as_xml
{
    my $self = shift;
    my %params = @_;

    my ($name_node, $document);

    unless ( $name_node = $params{name} )
    {
        $name_node = ref $self;
        $name_node =~ s/::/_/gs;
    }

    unless ( $document = $params{document} )
    {
        $document = XML::LibXML->createDocument( '1.0', $params{charset} || 'UTF-8' );
    }

    my $node = $document->createElement($name_node);

    my $addChild = sub {
            my $p = shift;
            my $v = shift;

            if ( ref $v )
            {

lib/Ambrosia/core/Object.pm  view on Meta::CPAN


=head2 clone ($deep)

Makes clone of object.
If C<$deep> is true it will create a deep clone.
And vice versa if C<$deep> is false it will create a simple clone.
If a field is a reference to some data then the field of simple clone will also refer to these data.

Note for deep clone: if any field is the reference to any object, this object will also be cloned but only if it has the method C<clone>

=head2 as_xml ($document, $charset, $name, $error_ignore, @methods)

Converts the object to the XML Document (L<XML::LibXML::Document>).
Is called with the following params

=over 4

=item document

The xml document. Optional. If not defined, the document will be created.

=item charset

Charset of xml document if it has not been defined. Optional. Default is 'utf8'.

=item name

Name of root node. Optional. If not presented, the class name will be used.

=item error_ignore ($bool)

True or false in perl notation (1 or 0). Optional. Default value is true.

script/ambrosia  view on Meta::CPAN

        ->new()
        ->on_error(sub {
                storage->foreach('cancel_transaction');
                die "@_";
            })
        ->on_complete(sub {
                if ( my $mng = $MANAGERS->{$action || Context->action} )
                {
                    if ( $mng->{template} )
                    {
                        my $xml = new Ambrosia::View::XSLT(charset => 'UTF-8', rootName => config()->ID)
                            ->render( $share_dir . $mng->{template}, Context->data);

                        my $doc = XML::LibXML->load_xml(string => $xml);
                        my $xmlschema = XML::LibXML::Schema->new( location => $share_dir . '/XSD/AmbrosiaDL.xsd' );
                        if ( eval { $xmlschema->validate( $doc ); 1; } )
                        {
                            if ( open(my $fh, '>', config()->ID . '.xml') )
                            {
                                print $fh $xml;
                                close $fh;

share/Managers/buildConfig.pm  view on Meta::CPAN

    ### enter name of project ###
    my $projectName = '';
    print 'Enter the name of project: ';
    $projectName = readln() or die 'Project must be named!';

    ### enter title of project ###
    my $projectTitle = '';
    print "Enter the title of project [$projectName]:";
    $projectTitle = readln() || $projectName;

    ### enter charset of project ###
    my $charset = '';
    print "Enter the charset of project for output results [utf-8]:";
    $charset = readln() || 'utf-8';

    ### enter path for root directory of project ###
    my $rootPath;
    while(1)
    {
        $rootPath = cwd();
        print "Enter the path for root directory of project [$rootPath]: ";
        $rootPath = readln() || abs_path($rootPath);

        unless ($rootPath && !isRootDir($rootPath))

share/Managers/buildConfig.pm  view on Meta::CPAN

    my $dbUser;
    print "Enter the username of database [root]:";
    $dbUser = readln() || 'root';

    ### enter password ###
    my $dbPassword;
    print "Enter user's password []:";
    $dbPassword = readln() || '';

    ### enter password ###
    my $dbCharset = lc($charset);
    $dbCharset =~ s/[^a-z0-9]//sg;
    print "Enter the charset of database [$dbCharset]:";
    $dbCharset = readln() || $dbCharset;

    ### enter password ###
    my $dbEngineParams = "database=$dbSchema;host=$dbHost" . ($dbPort ? ";port=$dbPort" : '');
    print "Enter the settings for connecting to the database as a string [$dbEngineParams]:";
    $dbEngineParams = readln() || 'undef';

    ### write config to file ###
    if ( open(my $fh, '>', $projectName . '.conf') )
    {
        my $template = join '', <Managers::buildConfig::DATA>;
        print $fh proces_template($template,
            NAME    => $projectName,
            TITLE   => $projectTitle,
            ROOT    => $rootPath,
            CHARSET => $charset,
            SHARE_DIR => Context->repository->get('SHARE_DIR'),
            PERL_LIB_PATH => "@perlLibPath",
            DOJO_TOOLKIT_PATH => $DojoToolkitPath,

            HTTP_SERVER_NAME  => $httpServerName,
            HTTP_PORT => $httpPort,

            DB_ENGINE   => $dbEngineName,
            DB_SCHEMA => $dbSchema,
            DB_HOST => $dbHost,

share/Managers/buildConfig.pm  view on Meta::CPAN


my $ROOT = '##ROOT##';

return
{
    #Application name
    ID => '##NAME##',
    #Application label (title)
    Label => '##TITLE##',

    #Template charset
    Charset => '##CHARSET##',

    #The path to templates of Ambrosia Builder
    TemplatePath  => '##SHARE_DIR##',

    #Now only so. Don't edit this.
    TemplateStyle => { jsframework => 'dojo', htmltemplate => 'xslt' },
    #You must load Dojo Toolkit 1.7.2 from http://download.dojotoolkit.org/release-1.7.2/dojo-release-1.7.2.tar.gz
    #and extract it into this directory
    DojoToolkitPath => '##DOJO_TOOLKIT_PATH##',

share/Managers/buildConfig.pm  view on Meta::CPAN

                user          => '##DB_USER##',
                password      => '##DB_PASSWORD##',
                ##DB_ENGINE_PARAMS##
                additional_params => { AutoCommit => 0, RaiseError => 1, LongTruncOk => 1 },
                additional_action => sub { my $dbh = shift; $dbh->do('SET NAMES ##DB_CHARSET##')},
            },
        ]
    },

    data_source_info => {
        DBI => { ##NAME## => {charset => '##DB_CHARSET##'} }
    },
};


share/Managers/buildXml.pm  view on Meta::CPAN

#   ambrosia -c ${projectName}.conf -d ${projectName}.xml -a xml2app
#
#######################################################################

MESSAGE

    chomp(my $hostname = `hostname`);
    Context->repository->set( config => {
            name     => config->ID,
            label    => config->Label,
            charset  => lc(config->Charset || 'utf-8'),
            hostname => config->hostname || $hostname,

            ServerName => config->ServerName,
            ServerPort => config->ServerPort,

            ProjectPath => abs_path($path_to_app),
            PerlLibPath => join(' ', map {abs_path($_)} split /\s+/, config->PerlLibPath),
        } );
    Context->repository->set( Message => $message );
}

share/Managers/buildXml.pm  view on Meta::CPAN

    push @$schema_list, $schema;

    my $ds = getDataSource($type, $source_name);

    $schema->{config} = {
        db_engine   => $ds->{engine_name},
        db_source   => $source_name,
        db_params   => $ds->{engine_params},
        db_user     => $ds->{user},
        db_password => $ds->{password},
        db_charset  => (config->data_source_info->{$type}->{$source_name}->{charset} || 'utf8'),
    };

    my $tables = table_info($driver);
    my %hTables = ();

    my %foreign_keys = ();
    foreach ( @{foreign_key_info($driver)} )
    {
        push @{$foreign_keys{$_->{pktable_name}}}, {
            fktable_name => $_->{fktable_name},

share/Templates/Common/HandlerModule.xsl  view on Meta::CPAN


    instance Ambrosia::Context(config->CommonGatewayInterface)
        ->on_start( sub {
                instance Ambrosia::Addons::Session(storage => new Ambrosia::Addons::Session::Cookie())
            } )
        ->on_abort( sub {session->destroy} )
        ->on_finish( sub {session->destroy} );

    instance Ambrosia::DataProvider(<xsl:value-of select="$RealAppName" /> => config->data_source);

    my $viewXML  = new Ambrosia::View::XSLT( charset => config->Charset, rootName => '<xsl:value-of select="$UcAppName" />' );
    my $viewJSON = new Ambrosia::View::JSON( charset => config->Charset );

    $dispatcher = Ambrosia::Dispatcher
        ->new()
<xsl:if test="/atns:Application/@Authorization!='NO'">
        ->on_check_access(\&amp;check_access)
</xsl:if>
        ->on_error(sub { error($_[1]) })
        ->on_complete(sub {
                Context->repository->set( __debug => config->DEBUG );
                if ( my $mng = shift )

share/Templates/Common/HandlerModule.xsl  view on Meta::CPAN

    storage->foreach('cancel_transaction');
    storage->foreach('close_connection');

    Context->print_response_header(
            -Content_type => 'text/html',
            -Charset      => config->Charset,
            -cookie       => session->getSessionValue,
        );

    $errmsg =~ s{\n}{}g;
    my $charset = config->Charset;
    print &lt;&lt;EOB;
<HTML>
<HEAD><TITLE>Error!</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=$charset" />
</HEAD>
<BODY>
<SPAN style="padding:30px;"><B><FONT color="red" size="+2"><BR/><BR/>$errmsg</FONT></B></SPAN>
</BODY>
</HTML>
EOB

    Context->abort_session();
}

share/Templates/Common/HandlerModule.xsl  view on Meta::CPAN

            $mng->{access}
        );

    if ( $result->IS_REDIRECT )
    {
        Context->redirect(
                -must_revalidate  => 1,
                -max_age  => 0,
                -no_cache => 1,
                -no_store => 1,
                -charset  => config->Charset,
                -uri      => (Context->proxy || Context->full_script_path) . $ENV{PATH_INFO},
                session->hasSessionData() ? (-cookie   => session->getSessionValue()) : (),
            );
        return 0;
    }

    controller->reset('/authorize') unless $result->IS_PERMIT;

    return 1;
}

share/Templates/Common/ServiceHandlerModule.xsl  view on Meta::CPAN


    our $dispatcher;
    our $Result;
    our $viewXML;
    our $viewJSON;
    BEGIN
    {
        instance Ambrosia::DataProvider( <xsl:value-of select="$RealAppName" /> => config->data_source);
        instance Ambrosia::Context();

        $viewXML  = new Ambrosia::View::XSLT( charset => config->Charset, rootName => '<xsl:value-of select="$UcAppName" />' );
        $viewJSON = new Ambrosia::View::JSON( charset => config->Charset );

        $dispatcher = Ambrosia::Dispatcher
            ->new()
            ->on_error(sub {
                    logger->error(@_);
                    storage->foreach('cancel_transaction');
                    storage->foreach('close_connection');
                    Context->error(@_);
                    die $@;
                })

share/Templates/Templates/XSLT+DOJO/authorize.xsl  view on Meta::CPAN


<xsl:template match="/"><xsl:text disable-output-escaping="yes">&lt;!DOCTYPE HTML>
</xsl:text>
<html lang="en">
	<xslt:if test="boolean(/Application/@Language)">
		<xslt:attribute name="lang">
			<xslt:value-of select="/Application/@Language"/>
		</xslt:attribute>
	</xslt:if>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<xslt:apply-imports/>
		<script type="text/javascript">
				require(["dijit/dijit","dijit/form/Form","dijit/form/Button","dijit/form/ValidationTextBox","dojo/domReady!","dojo/parser"]);
		</script>
	</head>
	<body class="claro">
		<xsl:apply-templates select="//repository/mng_EWM"/>
		<xsl:apply-templates>
			<xslt:attribute name="select"><xslt:value-of select="$UcAppName" /></xslt:attribute>
		</xsl:apply-templates>

share/Templates/Templates/XSLT+DOJO/edit_json.xsl  view on Meta::CPAN


<xsl:template match="/"><xsl:text disable-output-escaping="yes">&lt;!DOCTYPE HTML>
</xsl:text>
<html lang="en">
	<xslt:if test="boolean(/Application/@Language)">
		<xslt:attribute name="lang">
			<xslt:value-of select="/Application/@Language"/>
		</xslt:attribute>
	</xslt:if>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<xslt:apply-imports/>

		<script type="text/javascript">
			require([
			"dijit/dijit",
			"dijit/form/Form",
			"dijit/form/Button",
			"dijit/form/ValidationTextBox",
<xslt:for-each select="//atns:Application/atns:Entity/atns:Field[not(@Type=preceding-sibling::atns:Field/@Type)]">
	<xslt:choose>

share/Templates/Templates/XSLT+DOJO/list_json.xsl  view on Meta::CPAN

<xslt:template match="/">

<xsl:stylesheet version="1.0">

<xsl:output method="html" indent="yes" />

<xsl:template match="/"><xsl:text disable-output-escaping="yes">&lt;!DOCTYPE HTML>
</xsl:text>
<html xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<xslt:apply-imports/>

		<style type="text/css">
			@import "/ajax/libs/dojo/1.7.2/dojox/grid/resources/Grid.css";
			@import "/ajax/libs/dojo/1.7.2/dojox/grid/resources/claroGrid.css";

			.head {
				text-align:center;
				//font-weight:bold;
				font-size: 1.5em;

share/Templates/Templates/XSLT+DOJO/main.xsl  view on Meta::CPAN


<xsl:template match="/"><xsl:text disable-output-escaping="yes">&lt;!DOCTYPE HTML>
</xsl:text>
<html lang="en">
	<xslt:if test="boolean(/Application/@Language)">
		<xslt:attribute name="lang">
			<xslt:value-of select="/Application/@Language"/>
		</xslt:attribute>
	</xslt:if>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><xslt:value-of select="/atns:Application/@Label"/></title>
		<xslt:apply-imports/>

		<script type="text/javascript">
			require(["dijit/layout/ContentPane", "dijit/layout/BorderContainer", "dijit/layout/AccordionContainer", "dojo/parser"]);
		</script>

		<style type="text/css">
			#appLayout {
				height: 95%;

share/Templates/Templates/XSLT+DOJO/tree_json.xsl  view on Meta::CPAN


<xsl:template match="/"><xsl:text disable-output-escaping="yes">&lt;!DOCTYPE HTML>
</xsl:text>
<html lang="en">
	<xslt:if test="boolean(/Application/@Language)">
		<xslt:attribute name="lang">
			<xslt:value-of select="/Application/@Language"/>
		</xslt:attribute>
	</xslt:if>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<xslt:apply-imports/>
<xsl:variable name="url">
<xsl:value-of select="">
	<xslt:attribute name="select"><xslt:value-of select="concat('//',$UcAppName,'/@script')" /></xslt:attribute>
</xsl:value-of>/json/<xsl:value-of select="//repository/@Name"/>
</xsl:variable>
		<script type="text/javascript">
			require([
				"dojo/store/JsonRest",
				"dojo/store/Observable",

share/Templates/db2xml.xsl  view on Meta::CPAN


<xsl:template match="*">
	<Application Language="en-us" Authorization="YES">
		<xsl:attribute name="Name">
			<xsl:value-of select="name()" /><!-- name of root element. (config->ID) -->
		</xsl:attribute>
		<xsl:attribute name="Label">
			<xsl:value-of select="//repository/config/@label" /><!-- config->Label -->
		</xsl:attribute>
		<xsl:attribute name="Charset">
			<xsl:value-of select="//repository/config/@charset" /><!-- config->Charset -->
		</xsl:attribute>

		<Config>
			<CommonGatewayInterface Engine="ApacheRequest">
				<Params
					Pragma        = "no-cache"
					Cache_Control = "no-cache, must-revalidate, no-store"
				/>
			</CommonGatewayInterface>

share/Templates/db2xml.xsl  view on Meta::CPAN

			<xsl:attribute name="Schema">
				<xsl:value-of select="@schema" />
			</xsl:attribute>
			<xsl:attribute name="User">
				<xsl:value-of select="config/@db_user" />
			</xsl:attribute>
			<xsl:attribute name="Password">
				<xsl:value-of select="config/@db_password" />
			</xsl:attribute>
			<xsl:attribute name="Charset">
				<xsl:value-of select="config/@db_charset" />
			</xsl:attribute>
			<xsl:attribute name="Params">
				<xsl:value-of select="config/@db_params" />
			</xsl:attribute>
		</Source>
	</Type>
</xsl:template>

<!-- Create a list of Entities -->
<xsl:template match="//repository/schema_list/tables" mode="entity">



( run in 0.322 second using v1.01-cache-2.11-cpan-4d50c553e7e )