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/webapp/WEB-INF/templates/vm/portlets/html browser-psml.vm psml-form.vm
Date Tue, 13 Aug 2002 21:46:43 GMT
taylor      2002/08/13 14:46:43

  Modified:    src/java/org/apache/jetspeed/modules/actions/portlets
                        PsmlUpdateAction.java
               src/java/org/apache/jetspeed/om/dbpsml/map
                        JetspeedGroupProfileMapBuilder.java
                        JetspeedRoleProfileMapBuilder.java
                        JetspeedUserProfileMapBuilder.java
               webapp/WEB-INF/conf JetspeedSecurity.properties
               webapp/WEB-INF/templates/vm/portlets/html browser-psml.vm
                        psml-form.vm
  Log:
  - Patch from Mark Orciuch to Export PSML individual PSML resources to the file system.
  
  Revision  Changes    Path
  1.6       +266 -1    jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlUpdateAction.java
  
  Index: PsmlUpdateAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlUpdateAction.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PsmlUpdateAction.java	26 Jul 2002 01:47:20 -0000	1.5
  +++ PsmlUpdateAction.java	13 Aug 2002 21:46:42 -0000	1.6
  @@ -60,6 +60,9 @@
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.util.StringUtils;
   import org.apache.turbine.util.security.EntityExistsException;
  +import org.apache.turbine.services.TurbineServices;
  +import org.apache.turbine.services.servlet.TurbineServlet;
  +import org.apache.turbine.services.resources.ResourceService;
   
   // Velocity Stuff
   import org.apache.velocity.context.Context;
  @@ -67,6 +70,10 @@
   //Java
   import java.util.Vector;
   import java.util.Iterator;
  +import java.io.File;
  +import java.io.FileWriter;
  +import java.io.FileReader;
  +import java.io.IOException;
   
   //Jetspeed
   import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants;
  @@ -85,6 +92,21 @@
   import org.apache.jetspeed.util.template.JetspeedLink;
   import org.apache.jetspeed.util.template.JetspeedLinkFactory;
   import org.apache.jetspeed.services.resources.JetspeedResources;
  +import org.apache.jetspeed.services.psmlmanager.PsmlManagerService;
  +
  +//castor support
  +import org.exolab.castor.xml.MarshalException;
  +import org.exolab.castor.xml.Unmarshaller;
  +import org.exolab.castor.xml.Marshaller;
  +import org.exolab.castor.xml.ValidationException;
  +import org.exolab.castor.mapping.Mapping;
  +import org.exolab.castor.mapping.MappingException;
  +import org.xml.sax.InputSource;
  +
  +// serialization support
  +import org.apache.xml.serialize.Serializer;
  +import org.apache.xml.serialize.XMLSerializer;
  +import org.apache.xml.serialize.OutputFormat;
   
   /**
    * This action enables to update the psml entries
  @@ -101,6 +123,7 @@
       protected static final String CATEGORY_NAME = "categoryName";
       protected static final String CATEGORY_VALUE = "categoryValue";
       protected static final String COPY_FROM = "copyFrom";
  +    protected static final String COPY_TO = "copyTo";
       protected static final String TEMP_LOCATOR = "tempLocator";
       protected static final String PSML_UPDATE_PANE = "PsmlForm";
       /**
  @@ -206,6 +229,57 @@
                       context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
                   }
               }
  +
  +            if(mode != null && mode.equals("export"))
  +            {
  +                if (msgid == null)
  +                {
  +                    if(path == null)
  +                    {
  +                        context.put(COPY_TO, "c:/temp");
  +                        context.put(COPY_FROM, "user/anon/media-type/html/page/default.psml");
  +                    }
  +                    else
  +                    {
  +                        ProfileLocator tmpLocator = new BaseProfileLocator();
  +                        tmpLocator.createFromPath(path);
  +                        Profile profile = Profiler.getProfile(tmpLocator);
  +                        if (profile != null)
  +                        {
  +                            rundata.getUser().setTemp(TEMP_LOCATOR, tmpLocator);
  +                            context.put("profile", profile);
  +                        }
  +
  +                        String categoryName = "group";
  +                        String categoryValue = tmpLocator.getGroupName();
  +                        if (categoryValue == null)
  +                        {
  +                            categoryName = "role";
  +                            categoryValue = tmpLocator.getRoleName();
  +                            if (categoryValue == null)
  +                            {
  +                                categoryName = "user";
  +                                categoryValue = tmpLocator.getUserName();
  +                                if (categoryValue == null)
  +                                {
  +                                    categoryName = "user";
  +                                    categoryValue = "anon";
  +                                }
  +                            }
  +
  +                        }
  +
  +                        context.put(COPY_TO, "c:/temp/"+categoryValue+".psml");
  +                        context.put(COPY_FROM, path);
  +                    }
  +                }
  +                else
  +                {
  +                    context.put(COPY_TO, rundata.getUser().getTemp(COPY_TO));
  +                    context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
  +                }
  +            }
  +
           }
           catch (Exception e)
           {
  @@ -424,6 +498,197 @@
       {
           rundata.getUser().setTemp(PSML_REFRESH_FLAG, TRUE);
       }
  +
  +    /**
  +     * File Export Action for Psml.
  +     *
  +     * @param rundata The turbine rundata context for this request.
  +     * @param context The velocity context for this request.
  +     */
  +    public void doExport(RunData rundata, Context context)
  +        throws Exception
  +    {
  +        Profile profile = null;
  +        ProfileLocator locator = null;
  +        String copyTo = null;
  +        String copyFrom = null;
  +
  +        try
  +        {
  +            copyFrom = rundata.getParameters().getString("CopyFrom");
  +            copyTo = rundata.getParameters().getString("CopyTo");
  +
  +            //TODO: check if file already exists
  +            /*if (name == null || name.trim().length() == 0)
  +            {
  +                JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
  +                DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
  +                                      .addPathInfo(SecurityConstants.PARAM_MODE,
  +                                                   SecurityConstants.PARAM_MODE_INSERT)
  +                                      .addPathInfo(SecurityConstants.PARAM_MSGID,
  +                                                   SecurityConstants.MID_INVALID_ENTITY_NAME);
  +                JetspeedLinkFactory.putInstance(link);
  +                rundata.setRedirectURI(duri.toString());
  +
  +                //save user entered values
  +                if (copyTo != null)
  +                    rundata.getUser().setTemp(COPY_TO, copyTo);
  +                if (copyFrom != null)
  +                    rundata.getUser().setTemp(COPY_FROM, copyFrom);
  +                return;
  +            } */
  +
  +            //
  +            // retrieve the profile to clone
  +            //
  +            ProfileLocator baseLocator = new BaseProfileLocator();
  +            baseLocator.createFromPath(copyFrom);
  +            Profile baseProfile = Profiler.getProfile(baseLocator);
  +
  +            //
  +            // Export profile
  +            //
  +            if(baseProfile != null)
  +            {
  +                PSMLDocument doc = baseProfile.getDocument();
  +                if(doc != null)
  +                {
  +                    this.saveDocument(copyTo,doc);
  +                    rundata.setMessage("Profile ["+copyFrom+"] has been saved to disk in
["+copyTo+"]");
  +                }
  +            }
  +            else
  +            {
  +                Log.error("Profile listed in Copy From Not Found!");
  +            }
  +        }
  +        catch (Exception e)
  +        {
  +            // log the error msg
  +            Log.error(e);
  +
  +            //
  +            // dup key found - display error message - bring back to same screen
  +            //
  +            JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
  +            DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
  +                                  .addPathInfo(SecurityConstants.PARAM_MODE,
  +                                               "export")
  +                                  .addPathInfo(SecurityConstants.PARAM_MSGID,
  +                                               SecurityConstants.MID_UPDATE_FAILED);
  +            JetspeedLinkFactory.putInstance(link);
  +            rundata.setRedirectURI(duri.toString());
  +        }
  +        // save values that user just entered so they don't have to re-enter
  +        if (copyTo != null)
  +            rundata.getUser().setTemp(COPY_TO, copyFrom);
  +        if (copyFrom != null)
  +            rundata.getUser().setTemp(COPY_FROM, copyFrom);
  +
  +    }
  +
  +    /** Save the PSML document on disk to the specififed fileOrUrl
  +     * 
  +     * @param fileOrUrl a String representing either an absolute URL
  +     * or an absolute filepath
  +     * @param doc the document to save
  +     */
  +    private boolean saveDocument(String fileOrUrl, PSMLDocument doc)
  +    {
  +        boolean success = false;
  +        
  +        if (doc == null) return false;
  +        File f = new File(fileOrUrl);
  +
  +        FileWriter writer = null;
  +
  +        try
  +        {
  +            writer = new FileWriter(f);
  +            // create the serializer output format        
  +            OutputFormat format = new OutputFormat();
  +            format.setIndenting(true);
  +            format.setIndent(4);
  +            Serializer serializer = new XMLSerializer(writer,format); 
  +            Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
  +            marshaller.setMapping(this.loadMapping());
  +            marshaller.marshal(doc.getPortlets());
  +
  +            success = true;
  +        } 
  +        catch (MarshalException e)
  +        {
  +            Log.error("PSMLManager: Could not marshal the file "+f.getAbsolutePath(), e);
  +        }
  +        catch (MappingException e)
  +        {
  +            Log.error("PSMLManager: Could not marshal the file "+f.getAbsolutePath(), e);
  +        }
  +        catch (ValidationException e)
  +        {
  +            Log.error("PSMLManager: document "+f.getAbsolutePath()+" is not valid", e);
  +        }
  +        catch (IOException e)
  +        {
  +            Log.error("PSMLManager: Could not save the file "+f.getAbsolutePath(), e);
  +        }
  +        catch (Exception e)
  +        {
  +            Log.error("PSMLManager: Error while saving  "+f.getAbsolutePath(), e);
  +        }
  +        finally
  +        {
  +            try { writer.close(); } catch (IOException e) {}
  +        }   
  +        
  +        return success;
  +    }
  +
  +    /**
  +     * Loads psml mapping file
  +     * 
  +     * @exception Exception
  +     */
  +    private Mapping loadMapping()
  +        throws Exception
  +    {
  +        // get configuration parameters from Jetspeed Resources
  +        ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
  +                                                     .getResources(PsmlManagerService.SERVICE_NAME);
  +
  +        // test the mapping file and create the mapping object
  +        Mapping mapping = null;
  +        String mapFile = serviceConf.getString("mapping","${webappRoot}/WEB-INF/conf/psml-mapping.xml");
       
  +        mapFile = TurbineServlet.getRealPath( mapFile );        
  +        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 Exception("Error in mapping");
  +                }
  +            }
  +            else
  +            {
  +                throw new Exception("PSML Mapping not found or not a file or unreadable:
"+mapFile);
  +            }
  +        }
  +
  +        return mapping;
  +    }
  +
  +
   
   }
   
  
  
  
  1.12      +1 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/map/JetspeedGroupProfileMapBuilder.java
  
  Index: JetspeedGroupProfileMapBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/map/JetspeedGroupProfileMapBuilder.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JetspeedGroupProfileMapBuilder.java	7 Aug 2002 06:02:15 -0000	1.11
  +++ JetspeedGroupProfileMapBuilder.java	13 Aug 2002 21:46:42 -0000	1.12
  @@ -11,7 +11,7 @@
   /**
     *  This class was autogenerated by Torque on: 
     *
  -  * [Mon Aug 05 12:13:35 PDT 2002]
  +  * [Tue Aug 13 14:06:02 PDT 2002]
     *
     */
   public class JetspeedGroupProfileMapBuilder implements MapBuilder
  
  
  
  1.12      +1 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/map/JetspeedRoleProfileMapBuilder.java
  
  Index: JetspeedRoleProfileMapBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/map/JetspeedRoleProfileMapBuilder.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JetspeedRoleProfileMapBuilder.java	7 Aug 2002 06:02:15 -0000	1.11
  +++ JetspeedRoleProfileMapBuilder.java	13 Aug 2002 21:46:42 -0000	1.12
  @@ -11,7 +11,7 @@
   /**
     *  This class was autogenerated by Torque on: 
     *
  -  * [Mon Aug 05 12:13:35 PDT 2002]
  +  * [Tue Aug 13 14:06:02 PDT 2002]
     *
     */
   public class JetspeedRoleProfileMapBuilder implements MapBuilder
  
  
  
  1.12      +1 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/map/JetspeedUserProfileMapBuilder.java
  
  Index: JetspeedUserProfileMapBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbpsml/map/JetspeedUserProfileMapBuilder.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JetspeedUserProfileMapBuilder.java	7 Aug 2002 06:02:15 -0000	1.11
  +++ JetspeedUserProfileMapBuilder.java	13 Aug 2002 21:46:42 -0000	1.12
  @@ -11,7 +11,7 @@
   /**
     *  This class was autogenerated by Torque on: 
     *
  -  * [Mon Aug 05 12:13:35 PDT 2002]
  +  * [Tue Aug 13 14:06:02 PDT 2002]
     *
     */
   public class JetspeedUserProfileMapBuilder implements MapBuilder
  
  
  
  1.27      +0 -0      jakarta-jetspeed/webapp/WEB-INF/conf/JetspeedSecurity.properties
  
  Index: JetspeedSecurity.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/conf/JetspeedSecurity.properties,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  
  
  
  1.7       +3 -1      jakarta-jetspeed/webapp/WEB-INF/templates/vm/portlets/html/browser-psml.vm
  
  Index: browser-psml.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/templates/vm/portlets/html/browser-psml.vm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- browser-psml.vm	26 Jul 2002 01:47:22 -0000	1.6
  +++ browser-psml.vm	13 Aug 2002 21:46:43 -0000	1.7
  @@ -167,7 +167,9 @@
                       #set ($link2 = $jslink.setPaneByName("PsmlForm").addQueryData("mode","delete").addQueryData("entityid",
$!entry.Path))
                       <a style="font-size:10" href='$link2'>Delete</a>&nbsp;&nbsp;&nbsp;&nbsp;
                       #set ($link3 = $jslink.setPaneByName("PsmlForm").addQueryData("mode","insert").addQueryData("entityid",
$!entry.Path))
  -                    <a style="font-size:10" href='$link3'>Clone</a>
  +                    <a style="font-size:10" href='$link3'>Clone</a>&nbsp;&nbsp;&nbsp;&nbsp;
  +                    #set ($link4 = $jslink.setPaneByName("PsmlForm").addQueryData("mode","export").addQueryData("entityid",
$!entry.Path))
  +                    <a style="font-size:10" href='$link4'>Export</a>
                   </td>
               </tr>
           </table>
  
  
  
  1.5       +13 -4     jakarta-jetspeed/webapp/WEB-INF/templates/vm/portlets/html/psml-form.vm
  
  Index: psml-form.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/templates/vm/portlets/html/psml-form.vm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- psml-form.vm	3 Jul 2002 21:30:52 -0000	1.4
  +++ psml-form.vm	13 Aug 2002 21:46:43 -0000	1.5
  @@ -29,7 +29,7 @@
           <tr>
               #formReadOnlyCell ("Name" "Name" $profile.Name)
           </tr>
  -      #else
  +      #elseif (($mode == "insert"))
   
           <tr>
             <td bgcolor="$!{skin.TitleBackgroundColor}">
  @@ -120,8 +120,15 @@
           <tr>
               #formCell ("Copy From" "CopyFrom" $copyFrom)
           </tr>
  -      #end
  -
  +     #end   
  +     #if ($mode == "export")     
  +        <tr>
  +            #formCell ("Copy From" "CopyFrom" $copyFrom)
  +        </tr>
  +        <tr>
  +            #formCell ("Copy To" "CopyTo" $copyTo)
  +        </tr>
  +     #end    
     </table>
     <table border="0"  cellspacing="0" cellpadding="5" width="30%">
         <tr>
  @@ -130,6 +137,8 @@
               <input type="submit" name="eventSubmit_doInsert" value="Add Psml"/>
             #elseif ($mode == "delete")
               <input type="submit" name="eventSubmit_doDelete" value="Delete"/>
  +          #elseif ($mode == "export")
  +            <input type="submit" name="eventSubmit_doExport" value="Export Psml"/>
             #end
         </td>
         </form>
  
  
  

--
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