portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db DBUtils.java DatabasePsmlManagerService.java
Date Mon, 25 Mar 2002 07:33:32 GMT
taylor      02/03/24 23:33:32

  Modified:    src/java/org/apache/jetspeed/om/dbpsml
                        JetspeedAnonProfilePeer.java
                        JetspeedGroupProfilePeer.java
                        JetspeedRoleProfilePeer.java
                        JetspeedUserProfilePeer.java
               src/java/org/apache/jetspeed/services/psmlmanager
                        CastorPsmlManagerService.java
               src/java/org/apache/jetspeed/services/psmlmanager/db
                        DBUtils.java DatabasePsmlManagerService.java
  Log:
  - Completed conversion of PSML to Castor mapping for DB PSML
  
  Revision  Changes    Path
  1.3       +4 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/JetspeedAnonProfilePeer.java
  
  Index: JetspeedAnonProfilePeer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/JetspeedAnonProfilePeer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JetspeedAnonProfilePeer.java	6 Dec 2001 05:10:52 -0000	1.2
  +++ JetspeedAnonProfilePeer.java	25 Mar 2002 07:33:32 -0000	1.3
  @@ -23,6 +23,8 @@
   import org.apache.jetspeed.om.profile.ProfileLocator;
   import org.apache.jetspeed.services.psmlmanager.db.DBOperations;
   import org.apache.jetspeed.services.psmlmanager.db.DBUtils;
  +import org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManagerService;
  +import org.apache.jetspeed.services.PsmlManager;
   
   /** 
     *
  @@ -63,13 +65,14 @@
                              throws Exception
       {
           JetspeedAnonProfile anonProfile = new JetspeedAnonProfile();
  +        DatabasePsmlManagerService service = (DatabasePsmlManagerService)PsmlManager.getService();
   
           anonProfile.setMediaType(profile.getMediaType());
           anonProfile.setLanguage(profile.getLanguage());
           anonProfile.setCountry(profile.getCountry());
           anonProfile.setPage(profile.getName());
           anonProfile.setProfile(DBUtils.portletsToBytes(
  -                                       profile.getDocument().getPortlets()));
  +                                       profile.getDocument().getPortlets(), service.getMapping()));
   
           if (operation == INSERT)
           {
  
  
  
  1.3       +4 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/JetspeedGroupProfilePeer.java
  
  Index: JetspeedGroupProfilePeer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/JetspeedGroupProfilePeer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JetspeedGroupProfilePeer.java	6 Dec 2001 05:10:52 -0000	1.2
  +++ JetspeedGroupProfilePeer.java	25 Mar 2002 07:33:32 -0000	1.3
  @@ -21,6 +21,8 @@
   import org.apache.jetspeed.om.profile.ProfileLocator;
   import org.apache.jetspeed.services.psmlmanager.db.DBOperations;
   import org.apache.jetspeed.services.psmlmanager.db.DBUtils;
  +import org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManagerService;
  +import org.apache.jetspeed.services.PsmlManager;
   
   /** 
     * The skeleton for this class was autogenerated by Torque on:
  @@ -69,6 +71,7 @@
                              throws Exception
       {
           JetspeedGroupProfile groupProfile = new JetspeedGroupProfile();
  +        DatabasePsmlManagerService service = (DatabasePsmlManagerService)PsmlManager.getService();
   
           groupProfile.setGroupName(profile.getGroup().getName());
           groupProfile.setMediaType(profile.getMediaType());
  @@ -76,7 +79,7 @@
           groupProfile.setCountry(profile.getCountry());
           groupProfile.setPage(profile.getName());
           groupProfile.setProfile(DBUtils.portletsToBytes(
  -                                        profile.getDocument().getPortlets()));
  +                                        profile.getDocument().getPortlets(), service.getMapping()));
   
           if (operation == INSERT) 
           {
  
  
  
  1.3       +5 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/JetspeedRoleProfilePeer.java
  
  Index: JetspeedRoleProfilePeer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/JetspeedRoleProfilePeer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JetspeedRoleProfilePeer.java	6 Dec 2001 05:10:52 -0000	1.2
  +++ JetspeedRoleProfilePeer.java	25 Mar 2002 07:33:32 -0000	1.3
  @@ -21,6 +21,9 @@
   import org.apache.jetspeed.om.profile.ProfileLocator;
   import org.apache.jetspeed.services.psmlmanager.db.DBOperations;
   import org.apache.jetspeed.services.psmlmanager.db.DBUtils;
  +import org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManagerService;
  +import org.apache.jetspeed.services.PsmlManager;
  +
   
   /** 
     * The skeleton for this class was autogenerated by Torque on:
  @@ -69,6 +72,7 @@
                              throws Exception
       {
           JetspeedRoleProfile roleProfile = new JetspeedRoleProfile();
  +        DatabasePsmlManagerService service = (DatabasePsmlManagerService)PsmlManager.getService();
    
           roleProfile.setRoleName(profile.getRole().getName());
           roleProfile.setMediaType(profile.getMediaType());  
  @@ -76,7 +80,7 @@
           roleProfile.setCountry(profile.getCountry()); 
           roleProfile.setPage(profile.getName());
           roleProfile.setProfile(DBUtils.portletsToBytes(
  -                                       profile.getDocument().getPortlets()));
  +                                       profile.getDocument().getPortlets(), service.getMapping()));
   
           if (operation == INSERT)
           {
  
  
  
  1.3       +4 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/JetspeedUserProfilePeer.java
  
  Index: JetspeedUserProfilePeer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/JetspeedUserProfilePeer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JetspeedUserProfilePeer.java	6 Dec 2001 05:10:52 -0000	1.2
  +++ JetspeedUserProfilePeer.java	25 Mar 2002 07:33:32 -0000	1.3
  @@ -28,6 +28,8 @@
   import org.apache.jetspeed.om.profile.ProfileLocator;
   import org.apache.jetspeed.services.psmlmanager.db.DBOperations;
   import org.apache.jetspeed.services.psmlmanager.db.DBUtils;
  +import org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManagerService;
  +import org.apache.jetspeed.services.PsmlManager;
   
   /** 
     * The skeleton for this class was autogenerated by Torque on:
  @@ -75,6 +77,7 @@
                            throws Exception 
       {
           JetspeedUserProfile userProfile = new JetspeedUserProfile();
  +        DatabasePsmlManagerService service = (DatabasePsmlManagerService)PsmlManager.getService();
   
           userProfile.setUserName(profile.getUser().getUserName());
           userProfile.setMediaType(profile.getMediaType());
  @@ -82,7 +85,7 @@
           userProfile.setCountry(profile.getCountry());
           userProfile.setPage(profile.getName());
           userProfile.setProfile(DBUtils.portletsToBytes(
  -                                        profile.getDocument().getPortlets()));
  +                                        profile.getDocument().getPortlets(), service.getMapping()));
                                  
           if (operation == INSERT) 
           {
  
  
  
  1.18      +2 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java
  
  Index: CastorPsmlManagerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CastorPsmlManagerService.java	22 Mar 2002 18:51:56 -0000	1.17
  +++ CastorPsmlManagerService.java	25 Mar 2002 07:33:32 -0000	1.18
  @@ -79,6 +79,7 @@
   import org.apache.jetspeed.om.security.BaseJetspeedUser;
   import org.apache.turbine.om.security.TurbineRole;
   import org.apache.turbine.om.security.TurbineGroup;
  +import org.apache.turbine.services.TurbineServices;
   
   //castor support
   import org.exolab.castor.xml.MarshalException;
  @@ -117,7 +118,7 @@
    * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
    * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
    * @author <a href="mailto:sgala@apache.org">Santiago Gala</a>
  - * @version $Id: CastorPsmlManagerService.java,v 1.17 2002/03/22 18:51:56 taylor Exp $
  + * @version $Id: CastorPsmlManagerService.java,v 1.18 2002/03/25 07:33:32 taylor Exp $
    */
   public class CastorPsmlManagerService extends TurbineBaseService
       implements PsmlManagerService
  
  
  
  1.4       +5 -5      jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DBUtils.java
  
  Index: DBUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DBUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DBUtils.java	22 Mar 2002 18:51:57 -0000	1.3
  +++ DBUtils.java	25 Mar 2002 07:33:32 -0000	1.4
  @@ -80,7 +80,7 @@
    * This is a utility class used for database PSML implementation.
    *
    * @author <a href="mailto:adambalk@cisco.com">Atul Dambalkar</a>
  - * @version $Id: DBUtils.java,v 1.3 2002/03/22 18:51:57 taylor Exp $
  + * @version $Id: DBUtils.java,v 1.4 2002/03/25 07:33:32 taylor Exp $
    */
   public class DBUtils 
   {
  @@ -91,12 +91,12 @@
        * @param portletBytes Bytes array to load the PSML from
        * @return PSML structure Portlets object
        */
  -    public static Portlets bytesToPortlets(byte[] portletBytes) 
  +    public static Portlets bytesToPortlets(byte[] portletBytes, Mapping mapping) 
       {
           Reader reader = new StringReader(new String(portletBytes));
           try 
           {
  -            Unmarshaller unmarshaller = new Unmarshaller((Mapping)null);
  +            Unmarshaller unmarshaller = new Unmarshaller((Mapping)mapping);
               return (Portlets)unmarshaller.unmarshal(reader);
   
   //            return Portlets.unmarshal(reader);
  @@ -128,7 +128,7 @@
        * @param portlets the structure to convert to bytes array
        * @return Bytes array object for portles
        */
  -    public static byte[] portletsToBytes(Portlets portlets) 
  +    public static byte[] portletsToBytes(Portlets portlets, Mapping mapping) 
       {
           if (portlets == null)
           {
  @@ -143,7 +143,7 @@
   //            portlets.marshal(writer);
   
               Marshaller marshaller = new Marshaller(writer);
  -            marshaller.setMapping(null);
  +            marshaller.setMapping(mapping);
               marshaller.marshal(portlets);
   
               Log.debug("Portlets: " + writer.toString());
  
  
  
  1.14      +63 -9     jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DatabasePsmlManagerService.java
  
  Index: DatabasePsmlManagerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DatabasePsmlManagerService.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DatabasePsmlManagerService.java	22 Mar 2002 18:51:57 -0000	1.13
  +++ DatabasePsmlManagerService.java	25 Mar 2002 07:33:32 -0000	1.14
  @@ -83,6 +83,7 @@
   import org.apache.turbine.om.security.Role;
   import org.apache.turbine.util.db.pool.DBConnection;
   import org.apache.turbine.services.db.TurbineDB; 
  +import org.apache.turbine.services.servlet.TurbineServlet;
   
   //Servlet API
   import javax.servlet.ServletConfig;
  @@ -117,6 +118,12 @@
   import java.util.Vector;
   import java.util.WeakHashMap;
   import java.io.IOException;
  +import java.io.FileReader;
  +import java.io.File;
  +
  +import org.exolab.castor.mapping.Mapping;
  +import org.exolab.castor.mapping.MappingException;
  +import org.xml.sax.InputSource;
   
   
   /**
  @@ -125,7 +132,7 @@
    *
    * @author <a href="mailto:adambalk@cisco.com">Atul Dambalkar</a>
    * @author <a href="mailto:mvaidya@cisco.com">Medha Vaidya</a>
  - * @version $Id: DatabasePsmlManagerService.java,v 1.13 2002/03/22 18:51:57 taylor Exp
$
  + * @version $Id: DatabasePsmlManagerService.java,v 1.14 2002/03/25 07:33:32 taylor Exp
$
    */
   public class DatabasePsmlManagerService extends TurbineBaseService 
                                        implements PsmlManagerService, DBOperations
  @@ -145,6 +152,12 @@
       /** the import/export consumer service **/
       private PsmlManagerService consumer = null;
   
  +    // castor mapping
  +    public static final String DEFAULT_MAPPING = "${webappRoot}/WEB-INF/conf/psml-mapping.xml";
  +    String mapFile = null;
  +    /** the Castor mapping file name */
  +    private Mapping mapping = null;
  +
       /**
        * This is the early initialization method called by the
        * Turbine <code>Service</code> framework
  @@ -196,6 +209,11 @@
   
   //            new DatabaseInitializer(this, conf, serviceConf);
   
  +        // psml castor mapping file
  +        mapFile = serviceConf.getString("mapping",DEFAULT_MAPPING);
  +        mapFile = TurbineServlet.getRealPath( mapFile );
  +        loadMapping();
  +
           }
           catch (Throwable t)
           {
  @@ -224,6 +242,37 @@
           }   
       }
   
  +    protected void loadMapping()
  +        throws InitializationException
  +    {
  +        // test the mapping file and create the mapping object
  +        
  +        if (mapFile != null)
  +        {
  +            File map = new File(mapFile);
  +            Log.debug("Loading psml mapping file "+mapFile);
  +            if (map.exists() && map.isFile() && map.canRead())
  +            {
  +                try
  +                {
  +                    mapping = new Mapping();
  +                    InputSource is = new InputSource( new FileReader(map) );
  +                    is.setSystemId( mapFile );
  +                    mapping.loadMapping( is );
  +                }
  +                catch (Exception e)
  +                {
  +                    Log.error("Error in psml mapping creation",e);
  +                    throw new InitializationException("Error in mapping",e);
  +                }
  +            }
  +            else
  +            {
  +                throw new InitializationException("PSML Mapping not found or not a file
or unreadable: "+mapFile);
  +            }
  +        }
  +    }
  +
       /**
        * This is the shutdown method called by the
        * Turbine <code>Service</code> framework
  @@ -774,21 +823,21 @@
   
               if (obj instanceof JetspeedUserProfile) 
               {
  -                portlets = DBUtils.bytesToPortlets(((JetspeedUserProfile)obj).getProfile());
  +                portlets = DBUtils.bytesToPortlets(((JetspeedUserProfile)obj).getProfile(),
this.mapping);
               }
               else if (obj instanceof JetspeedGroupProfile) 
               {
  -                portlets = DBUtils.bytesToPortlets(((JetspeedGroupProfile)obj).getProfile());
  +                portlets = DBUtils.bytesToPortlets(((JetspeedGroupProfile)obj).getProfile(),
this.mapping);
   
               }
               else if (obj instanceof JetspeedRoleProfile) 
               {
  -                portlets = DBUtils.bytesToPortlets(((JetspeedRoleProfile)obj).getProfile());
  +                portlets = DBUtils.bytesToPortlets(((JetspeedRoleProfile)obj).getProfile(),
this.mapping);
    
               }
               else if (obj instanceof JetspeedAnonProfile) 
               {
  -                portlets = DBUtils.bytesToPortlets(((JetspeedAnonProfile)obj).getProfile());
  +                portlets = DBUtils.bytesToPortlets(((JetspeedAnonProfile)obj).getProfile(),
this.mapping);
               }
    
               list.add(portlets);
  @@ -882,7 +931,7 @@
                       JetspeedUserProfile uprofile = 
                                          (JetspeedUserProfile)iterator.next();
                       page = uprofile.getPage();
  -                    portlets = DBUtils.bytesToPortlets(uprofile.getProfile());
  +                    portlets = DBUtils.bytesToPortlets(uprofile.getProfile(), this.mapping);
                   }
               }
               else if (role != null)
  @@ -895,7 +944,7 @@
                       JetspeedRoleProfile rprofile = 
                                          (JetspeedRoleProfile)iterator.next();
                       page = rprofile.getPage();
  -                    portlets = DBUtils.bytesToPortlets(rprofile.getProfile());
  +                    portlets = DBUtils.bytesToPortlets(rprofile.getProfile(), this.mapping);
                   }
               } 
               else if (group != null)
  @@ -908,7 +957,7 @@
                       JetspeedGroupProfile gprofile = 
                                          (JetspeedGroupProfile)iterator.next();
                       page = gprofile.getPage();
  -                    portlets = DBUtils.bytesToPortlets(gprofile.getProfile());
  +                    portlets = DBUtils.bytesToPortlets(gprofile.getProfile(), this.mapping);
                   }
               }  
               else  // it will be anonymous access
  @@ -921,7 +970,7 @@
                       JetspeedAnonProfile aprofile = 
                                          (JetspeedAnonProfile)iterator.next();
                       page = aprofile.getPage();
  -                    portlets = DBUtils.bytesToPortlets(aprofile.getProfile());
  +                    portlets = DBUtils.bytesToPortlets(aprofile.getProfile(), this.mapping);
                   }
               }
               if (page != null && portlets != null) 
  @@ -1046,5 +1095,10 @@
           return count;
       }
   
  +
  +    public Mapping getMapping()
  +    {
  +        return this.mapping;
  +    }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message