You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Rhys Dixon <rh...@dyxn.net> on 2001/12/06 23:57:36 UTC

extending the torque demo app

hi all,

i made a set of torque templates that generates all of the
list/view/add/edit/delete
screens, actions, velocity pages using peers, turbine and velocity pages.

this is written for the june tdk (old torque) since that's the last tdk that
worked correctly for me.

regards,
rhys

here is one file:



package ${managerPackage};

$license
## this is a translation of SQL.java from the demo

## @author <a href="mailto:rhys@dyxn.net">Rhys Dixon</a>

/**
 *
 * This class was autogenerated by Torque : $now
 *
 * @author <a href="mailto:$email">$name</a>
 */


import org.apache.velocity.context.Context;

import org.apache.turbine.util.RunData;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.modules.actions.VelocitySecureAction;
import org.apache.turbine.services.security.TurbineSecurity;
import org.apache.turbine.util.security.AccessControlList;

import ${targetPackage}.${table.JavaName};
import ${targetPackage}.${table.JavaName}Peer;

public class ${table.JavaName}Manager extends VelocitySecureAction
{
    public void doInsert(RunData data, Context context)
        throws Exception
    {
 System.out.println("inserting new ${table.JavaName}");
        ${table.JavaName} entry = new ${table.JavaName}();
        data.getParameters().setProperties(entry);
        entry.save();
 System.out.println("after inserting new ${table.JavaName}");
    }
    /*
    public void doUpdate(RunData data, Context context)
        throws Exception
    {
 System.out.println("updating ${table.JavaName}");
        ${table.JavaName} entry = new ${table.JavaName}();
        data.getParameters().setProperties(entry);
 System.out.println("updating ${table.JavaName} with
id#"+entry.get${table.JavaName}Id());
 ${table.JavaName}Peer.doUpdate(entry);

 System.out.println("after updating ${table.JavaName}");
 }
 */

    public void doUpdate(RunData data, Context context)
        throws Exception
    {
        ${table.JavaName} entry = new ${table.JavaName}();
        data.getParameters().setProperties(entry);
        entry.setModified(true);
        entry.setNew(false);
        entry.save();
    }




    public void doDelete(RunData data, Context context)
        throws Exception
    {
 System.out.println("deleting from ${table.JavaName}");
        Criteria criteria = new Criteria();
 #set ( $idname = $table.JavaName.toUpperCase() )
        criteria.add(${table.JavaName}Peer.${idname}_ID,
data.getParameters().getInt("${table.name}id"));
        ${table.JavaName}Peer.doDelete(criteria);
 System.out.println("after deleting from ${table.JavaName}");
    }

    public void doPerform(RunData data, Context context)
        throws Exception
    {
 System.out.println("in ${table.JavaName}Manager.doPerform");
        data.setMessage("Can't find the button!<br />");
    }


    protected boolean isAuthorized( RunData data ) throws Exception
    {
        System.out.println("in ${table.JavaName}Manager.isAuthorized");
        boolean isAuthorized = false;

        /*
         * Get acl and check security.
         */
        AccessControlList acl = data.getACL();

        if (acl == null
                        || ! acl.hasPermission("Insert_${table.JavaName}")
                        || ! acl.hasPermission("Update_${table.JavaName}")
                        || ! acl.hasPermission("Delete_${table.JavaName}")
                        )
        {
                data.addMessage("You are not authorized in this area<br
/>");
  System.out.println("You are not authorized in this area<br />");
             isAuthorized = false;
        }
        else if(
data.getParameters().getString("eventSubmit_doInsert","").equals("Insert")
&&
acl.hasPermission("Insert_${table.JavaName}"))
                {
                data.addMessage("You are authorized to add to
${table.JavaName}");
                System.out.println("You are authorized to add to
${table.JavaName}<br />");
                isAuthorized = true;
                }
        else if(
data.getParameters().getString("eventSubmit_doUpdate","").equals("Update")
&&
acl.hasPermission("Update_${table.JavaName}"))
                {
                data.addMessage("You are authorized to update entries in
${table.JavaName}");
                System.out.println("You are authorized to update entries in
${table.JavaName}<br />");
                isAuthorized = true;
                }
        else if(
data.getParameters().getString("eventSubmit_doDelete","").equals("Delete")
&&
acl.hasPermission("Delete_${table.JavaName}"))
                {
                data.addMessage("You are authorized to delete from
${table.JavaName}<br />");
                System.out.println("You are authorized to delete from
${table.JavaName}");
                isAuthorized = true;
                }
        return isAuthorized;

    }




}



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
here's torque writing velocity:
this makes a page that lists all entries in a table (for each table)
it sure would be nice to have working tdk with the new torque

regards,
rhys




#set ( $quote = '"' )
#set ( $pound = '#' )
#set ( $dollar = '$' )
#set ( $ob = '{' )
#set ( $cb = '}' )


#if($data.getMessage())
Message: $data.getMessage()
#end

${pound}if ($entries)
<table>
  <tr>
    <td>
      <table cellspacing="1" cellpadding="1">
        <tr>
 #foreach ($col in $table.Columns)
      #set ( $cfc=$col.JavaName )
      #set ( $clow=$col.Name.toLowerCase() )
            ${pound}headerCell ("${cfc}")
 #end
        </tr>

        ${pound}foreach ($entry in $entries)
        <tr>
#set ($i=0)
#foreach ($col in $table.Columns)
 #if ($i>0)
    #set ( $cfc=$col.JavaName )
    #set ( $clow=$col.Name.toLowerCase() )
        ${pound}entryCell ($entry.${cfc})
 #end
#set ($i=1)
#end
#set ( $thisid = ${table.JavaName} )
          <td><a
href="${dollar}link.setPage(${quote}${table.JavaName}Edit.vm${quote}).addPat
hInfo(${quote}${table.Name}_ID${quote},
${dollar}${ob}entry.${thisid}Id${cb})">Edit</a></td>
        </tr>
        ${pound}end
      </table>
    </td>
  </tr>
</table>
${pound}end




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
here's velocity generation for edit pages.
boy, i wish i had a tdk with the new torque.


regards,
rhys







## @author <a href="mailto:rhys@dyxn.net">Rhys Dixon</a>

$page.setTitle("Edit")
#set ($dollar = '$')
#set ($ob = '{')
#set ($cb = '}')
#set ($quote = '"')
#set ($pound = '#')

${pound}if(${dollar}data.getMessage())
Message: ${dollar}data.getMessage()
${pound}end

#set ($formtag = "<form method=")
#set ($formtag = $strings.concat([$formtag,${quote}]))
#set ($formtag = $strings.concat([$formtag,"post"]))
#set ($formtag = $strings.concat([$formtag,${quote}])) action="]))
#set ($formtag = $strings.concat([$formtag,${quote}]))
#set ($formtag = $strings.concat([$formtag,"$link.setPage(>"]) )
$formtag
  <div align="left">
    <table bgcolor="#ffffff" cellpadding="5">
#set ($i=0)
#foreach ($col in $table.Columns)
 #if($i > 0)
    #set ($cfc=$col.JavaName)
    #set ($clow=$col.Name.toLowerCase())
      <tr>
        #formCell ("${cfc}" "${clow}" $entry.${cfc})
      </tr>
 #end
#set ($i=1)
#end

    </table>
#set ($thisid = ${table.JavaName})
#set ($tolower=$table.Name.toLowerCase())
    <input type="hidden" name="${tolower}id"
value="${dollar}${ob}entry.${thisid}id${cb}"/>
    <input type="submit" name="eventSubmit_doInsert" value="Insert"/>
    <input type="submit" name="eventSubmit_doUpdate" value="Update"/>
    <input type="submit" name="eventSubmit_doDelete" value="Delete"/>
  </div>
</form>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
i suppose that if one listed their entries, they would want to edit them...

regards,
rhys






package ${viewlistPackage};

$license

## this is a translation of Form.java from the demo

## @author <a href="mailto:rhys@dyxn.net">Rhys Dixon</a>

/**
 *
 * This class was autogenerated by Torque : $now
 *
 * @author <a href="mailto:$email">$name</a>
 */


import java.util.Vector;

import org.apache.turbine.modules.screens.VelocitySecureScreen;
import org.apache.turbine.util.RunData;

import org.apache.turbine.util.db.Criteria;

import ${targetPackage}.${table.JavaName};
import ${targetPackage}.${table.JavaName}Peer;

import org.apache.velocity.context.Context;

public class ${table.JavaName}Edit extends VelocitySecureScreen
{
    public void doBuildTemplate( RunData data, Context context )
    {
 System.out.println("in ${table.JavaName} Edit");
        try
        {
 #set ( $idname = $table.JavaName.toUpperCase() )
            int entry_id = data.getParameters().getInt("${idname}_ID");
            Criteria criteria = new Criteria();
            criteria.add(${table.JavaName}Peer.${idname}_ID, entry_id);
            ${table.JavaName} datatype = (${table.JavaName})
${table.JavaName}Peer.doSelect(criteria).elementAt(0);
            context.put("entry", datatype);
        }
        catch (Exception e)
        {
            // log something ?
        }
    }

    protected boolean isAuthorized( RunData data ) throws Exception
    {
        System.out.println("in ${table.JavaName}List.isAuthorized");
        boolean isAuthorized = false;

        /*
         * Get acl and check security.
         */
        AccessControlList acl = data.getACL();

        if (   acl == null
                        || ! acl.hasPermission("View_${table.JavaName}")
                     )
         {
                data.addMessage("You are not authorized in this area");
    System.out.println("Unauthorized user attepted to access
${table.JavaName}: Denying");
             isAuthorized = false;
        }
        else if( acl.hasPermission("View_${table.JavaName}"))
                {
                data.addMessage("You are authorized to view an entry in
${table.JavaName}");
                System.out.println("User is authorized to view an entry in
${table.JavaName}");
                isAuthorized = true;
                }
        return isAuthorized;

    }


}



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: extending the torque demo app

Posted by Rhys Dixon <rh...@dyxn.net>.
here's the java behind the list.vm that i just posted.

regards,
rhys



package ${viewlistPackage};

$license
## this is a translation of Index.java from the demo

## @author <a href="mailto:rhys@dyxn.net">Rhys Dixon</a>

/**
 *
 * This class was autogenerated by Torque : $now
 *
 * @author <a href="mailto:$email">$name</a>
 */


import java.util.Vector;

import org.apache.turbine.modules.screens.VelocitySecureScreen;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.security.AccessControlList;

import org.apache.turbine.util.db.Criteria;
import ${targetPackage}.${table.JavaName}Peer;

import org.apache.velocity.context.Context;

public class ${table.JavaName}List extends VelocitySecureScreen
{
    public void doBuildTemplate( RunData data, Context context )
    {
        context.put("entries", getEntries());
    }

    private Vector getEntries()
    {
        try
        {
  System.out.println("in ${table.JavaName} list");
            Criteria criteria = new Criteria();
            return ${table.JavaName}Peer.doSelect(criteria);
        }
        catch (Exception e)
        {
            return null;
        }
    }
    protected boolean isAuthorized( RunData data ) throws Exception
    {
        System.out.println("in ${table.JavaName}List.isAuthorized");
        boolean isAuthorized = false;

        /*
         * Get acl and check security.
         */
        AccessControlList acl = data.getACL();

        if (   acl == null
                        || ! acl.hasPermission("List_${table.JavaName}")
                     )
         {
                data.addMessage("You are not authorized in this area");
    System.out.println("Unauthorized user attepted to access
${table.JavaName}: Denying");
             isAuthorized = false;
        }
        else if( acl.hasPermission("List_${table.JavaName}"))
                {
                data.addMessage("You are authorized to list entries in ${tab
le.JavaName}");
                System.out.println("User is  authorized to list entries in
${table.JavaName}");
                isAuthorized = true;
                }
        return isAuthorized;

    }

}



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>