You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tdk-dev@turbine.apache.org by mp...@apache.org on 2001/07/13 22:56:28 UTC

cvs commit: jakarta-turbine-tdk/src/share/sample30/src/java/modules/tags UserInfoTag.java

mpoeschl    01/07/13 13:56:28

  Added:       src/share/sample30/src/java/modules/actions
                        SecureAction.java Upload.java SQL.java
               src/share/sample30/src/java/modules/screens BSF.java
                        Form.java Index.java ServletInfo.java
                        SecureScreen.java
               src/share/sample30/src/java/modules/tags UserInfoTag.java
  Log:
  add updated sample-app for turbine-3.0
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/actions/SecureAction.java
  
  Index: SecureAction.java
  ===================================================================
  package @TARGET_PACKAGE@.modules.actions;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.turbine.RunData;
  import org.apache.turbine.modules.actions.TemplateSecureAction;
  import org.apache.turbine.services.security.TurbineSecurity;
  import org.apache.turbine.util.security.AccessControlList;
  import org.apache.turbine.TemplateContext;
  
  /**
   * Velocity Secure action.
   *
   * Always performs a Security Check that you've defined before
   * executing the doBuildtemplate().
   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
   * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
   * @author <a href="mailto:john@zenplex.com">John Thorhauer</a>
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   */
  public class SecureAction 
      extends TemplateSecureAction
  {
      /**
       * Implement this to add information to the context.
       *
       * @param data Turbine information.
       * @param context Context for web pages.
       * @exception Exception, a generic exception.
       */
      public void doPerform( RunData data, TemplateContext context )
          throws Exception
      {
      }
  
      /**
       * This currently only checks to make sure that user is allowed to
       * view the storage area.  If you create an action that requires more
       * security then override this method.
       *
       * @param data Turbine information.
       * @return True if the user is authorized to access the screen.
       * @exception Exception, a generic exception.
       */
      protected boolean isAuthorized( RunData data ) throws Exception
      {
          boolean isAuthorized = false;
          
          // Get acl and check security.
          AccessControlList acl = data.getACL();
          
          if (acl == null || ! acl.hasRole("turbine_root"))
          {
              isAuthorized = false;
          }
          else if(acl.hasRole("turbine_root"))
          {
              isAuthorized = true;
          }
  
          return isAuthorized;
      }
  }
  
  
  
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/actions/Upload.java
  
  Index: Upload.java
  ===================================================================
  package @TARGET_PACKAGE@.modules.actions;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.File;
  import org.apache.turbine.Turbine;
  import org.apache.turbine.RunData;
  import org.apache.turbine.services.upload.FileItem;
  import org.apache.turbine.TemplateContext;
  
  /**
   * Class responsible for performing the company admin actions
   * in the Tambora Storage system.
   *
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   */
  public class Upload 
      extends SecureAction
  {
      /**
       * Upload the DTDs for this company.
       */
      public void doUpload(RunData data, TemplateContext context)
          throws Exception
      {
          FileItem fileItem = data.getParameters().getFileItem("file");
          fileItem.write(Turbine.getRealPath("/uploaded.file"));
      }
  
      /**
       * Default action to perform if the specified action
       * cannot be executed.
       */
      public void doPerform( RunData data, TemplateContext context )
          throws Exception
      {
          data.setMessage("Can't find the requested action! ");
      }
  }
  
  
  
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/actions/SQL.java
  
  Index: SQL.java
  ===================================================================
  package @TARGET_PACKAGE@.modules.actions;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.turbine.RunData;
  import org.apache.turbine.TemplateContext;
  import org.apache.turbine.util.db.Criteria;
  import @TARGET_PACKAGE@.om.Rdf;
  import @TARGET_PACKAGE@.om.RdfPeer;
  
  /**
   * This class provides a simple set of methods to
   * insert/update/delete records in a database.
   */
  public class SQL 
      extends SecureAction
  {
      /**
       * This simply takes an entry from the web form and
       * inserts it directly into the database.
       *
       * This would not be good in practice as the
       * data should be verified before being allowed
       * into the database. This is merely an
       * example of how to use peers, this certainly
       * wouldn't be secure.
       */
      public void doInsert(RunData data, TemplateContext context)
          throws Exception
      {
          Rdf entry = new Rdf();
          data.getParameters().setProperties(entry);
          entry.save();
      }
      
      /**
       * Update a record in the database with the
       * information present in the web form.
       *
       * Again, this is merely an example. The data
       * should be checked before being allowed
       * into the database.
       */
      public void doUpdate(RunData data, TemplateContext context)
          throws Exception
      {
          Rdf entry = new Rdf();
          data.getParameters().setProperties(entry);
          entry.setModified(true);
          entry.setNew(false);
          entry.save();
      }
  
      /**
       * Delete a record from the database using
       * the unique id gleaned from the web form.
       */
      public void doDelete(RunData data, TemplateContext context)
          throws Exception
      {
          Criteria criteria = new Criteria();
          criteria.add(RdfPeer.RDF_ID, data.getParameters().getInt("rdfid"));
          RdfPeer.doDelete(criteria);
      }
  
      /**
       * This is used in the event that the doInsert
       * above fails.
       */
      public void doPerform(RunData data, TemplateContext context)
          throws Exception
      {
          data.setMessage("Can't find the button!");
      }
  }
  
  
  
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/screens/BSF.java
  
  Index: BSF.java
  ===================================================================
  package @TARGET_PACKAGE@.modules.screens;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.turbine.RunData;
  import org.apache.turbine.TemplateContext;
  import org.apache.turbine.services.bsf.TurbineBSF;
  
  /**
   * Grab all the records in a table using a Peer, and
   * place the Vector of data objects in the context
   * where they can be displayed by a #foreach loop.
   *
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   */
  public class BSF 
      extends SecureScreen
  {
      /**
       * Place all the data object in the context
       * for use in the template.
       */
      public void doBuildTemplate( RunData data, TemplateContext context )
      {
          TurbineBSF.execute("helloWorld");        
      }
  }
  
  
  
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/screens/Form.java
  
  Index: Form.java
  ===================================================================
  package @TARGET_PACKAGE@.modules.screens;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.Vector;
  import org.apache.turbine.RunData;
  import org.apache.turbine.util.db.Criteria;
  import org.apache.turbine.TemplateContext;
  import @TARGET_PACKAGE@.om.Rdf;
  import @TARGET_PACKAGE@.om.RdfPeer;
  
  /**
   * Grabs a record from a database and makes
   * the data available in the template.
   *
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   */
  public class Form 
      extends SecureScreen
  {
      /**
       * Grab a record from the database based on the entry_id
       * found in the form. Make the data available in the
       * template.
       */
      public void doBuildTemplate( RunData data, TemplateContext context )
      {
          try
          {
              int entry_id = data.getParameters().getInt("rdfid");
              Criteria criteria = new Criteria();
              criteria.add(RdfPeer.RDF_ID, entry_id);
              Rdf rdf = (Rdf) RdfPeer.doSelect(criteria).elementAt(0);
              context.put("entry", rdf);            
          }
          catch (Exception e)
          {
              // log something ?
          }
      }
  }
  
  
  
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/screens/Index.java
  
  Index: Index.java
  ===================================================================
  package @TARGET_PACKAGE@.modules.screens;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.Vector;
  import org.apache.turbine.RunData;
  import org.apache.turbine.util.db.Criteria;
  import org.apache.turbine.TemplateContext;
  import @TARGET_PACKAGE@.om.RdfPeer;
  
  /**
   * Grab all the records in a table using a Peer, and
   * place the Vector of data objects in the context
   * where they can be displayed by a #foreach loop.
   *
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   */
  public class Index 
      extends SecureScreen
  {
      /**
       * Place all the data object in the context
       * for use in the template.
       */
      public void doBuildTemplate( RunData data, TemplateContext context )
      {
          context.put("entries", getEntries());
      }
  
      /**
       * This will return all the rdf records in
       * the database but they have been mapped to
       * Rdf objects so they can be directly used
       * in the Velocity template.
       */
      private Vector getEntries()
      {
          try
          {
              Criteria criteria = new Criteria();
              return RdfPeer.doSelect(criteria);
          }
          catch (Exception e)
          {
              return null;
          }
      }
  }
  
  
  
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/screens/ServletInfo.java
  
  Index: ServletInfo.java
  ===================================================================
  package @TARGET_PACKAGE@.modules.screens;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.turbine.Turbine;
  import org.apache.turbine.RunData;
  import org.apache.turbine.TemplateContext;
  
  /**
   * Grab all the records in a table using a Peer, and
   * place the Vector of data objects in the context
   * where they can be displayed by a #foreach loop.
   *
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   */
  public class ServletInfo 
      extends SecureScreen
  {
      /**
       * Place all the data object in the context
       * for use in the template.
       */
      public void doBuildTemplate( RunData data, TemplateContext context )
      {
          context.put("serverName", Turbine.getServerName());
      }
  }
  
  
  
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/screens/SecureScreen.java
  
  Index: SecureScreen.java
  ===================================================================
  package @TARGET_PACKAGE@.modules.screens;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.Vector;
  import org.apache.turbine.Turbine;
  import org.apache.turbine.RunData;
  import org.apache.turbine.TemplateContext;
  import org.apache.turbine.util.security.AccessControlList;
  import org.apache.turbine.modules.screens.TemplateSecureScreen;
  
  /**
   * Grab all the records in a table using a Peer, and
   * place the Vector of data objects in the context
   * where they can be displayed by a #foreach loop.
   *
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   */
  public class SecureScreen 
      extends TemplateSecureScreen
  {
      public void doBuildTemplate(RunData data, TemplateContext context)
          throws Exception
      {
      }
  
      /**
       * Overide this method to perform the security check needed.
       *
       * @param data Turbine information.
       * @return True if the user is authorized to access the screen.
       * @exception Exception, a generic exception.
       */
      protected boolean isAuthorized( RunData data )  
          throws Exception
      {
          boolean isAuthorized = false;
  
          AccessControlList acl = data.getACL();
          
          if (acl==null || ! acl.hasRole("turbine_root"))
          {
              data.setTarget(Turbine.getConfiguration().getString("template.login"));
              isAuthorized = false;
          }
          else if(acl.hasRole("turbine_root"))
          {
              isAuthorized = true;
          }
          return isAuthorized;
      }
  }
  
  
  
  1.1                  jakarta-turbine-tdk/src/share/sample30/src/java/modules/tags/UserInfoTag.java
  
  Index: UserInfoTag.java
  ===================================================================
  package @TARGET_PACKAGE@.tags;
  
  import java.io.IOException;
  
  import javax.servlet.jsp.tagext.TagSupport;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  
  import org.apache.turbine.RunData;
  import org.apache.turbine.services.jsp.JspService;
  import org.apache.turbine.om.security.User;
  
  /**
   * UserInfoTag is a sample JSP tag handler that displays the full
   * name of the user that is currently logged in.
   */
  
  public class UserInfoTag extends TagSupport
  {
    /**
     * Process the StartTag event
     *
     * @exception JspException
     */
  
    public int doStartTag() throws JspException
    {
  
      // Get the Turbine "RunData" object that was stuffed into the Http request.
  
      RunData data = (RunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
  
      // If we have a RunData object, get the User object
  
      if (data != null)
      {
        User user = data.getUser();
  
        // Write out the user's full name (last name, first name)
  
        try
        {
          String fullName = user.getFirstName() + " " + user.getLastName();
          pageContext.getOut().print(fullName);
        }
        catch (IOException e)
        {
          throw new JspException("I/O Exception: " + e.getMessage());
        }
      }
  
      return SKIP_BODY;
    }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-tdk-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-tdk-dev-help@jakarta.apache.org