You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by vk...@apache.org on 2008/10/15 18:09:19 UTC

svn commit: r704947 - in /portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools: pom.xml src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeployUtils.java

Author: vkumar
Date: Wed Oct 15 09:09:18 2008
New Revision: 704947

URL: http://svn.apache.org/viewvc?rev=704947&view=rev
Log:
Deploying PSML with portlet application. 
Place your all psml and link files, under psml folder 
/WEB-INF/psml

Jetspeed-2 will update pages, in database or in file system 
https://issues.apache.org/jira/browse/JS2-910

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeployUtils.java   (with props)
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/pom.xml
    portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/pom.xml?rev=704947&r1=704946&r2=704947&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/pom.xml Wed Oct 15 09:09:18 2008
@@ -44,6 +44,11 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>jetspeed-commons</artifactId>
+      <scope>provided</scope>
+    </dependency>    
+    <dependency>
       <groupId>jdom</groupId>
       <artifactId>jdom</artifactId>
     </dependency>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java?rev=704947&r1=704946&r2=704947&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java Wed Oct 15 09:09:18 2008
@@ -16,11 +16,13 @@
  */
 package org.apache.jetspeed.tools.deploy;
 
+import java.io.BufferedOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.File;
+import java.io.OutputStream;
 import java.nio.channels.FileChannel;
 import java.util.Enumeration;
 import java.util.jar.JarFile;
@@ -91,16 +93,28 @@
     public JetspeedDeploy(String inputName, String outputName, String contextName, boolean stripLoggers, String forcedVersion) throws Exception
     {
         File tempFile = null;
+        File tempPsmlDir = null;
         JarFile jin = null;
         JarOutputStream jout = null;
         FileChannel srcChannel = null;
         FileChannel dstChannel = null;
-
+        InputStream inputStream = null;
+        OutputStream outputStream = null; 
+        byte[] buffer = new byte[1024];
+        int len;
+        String destPath =null;
+        JetspeedDeployUtils utils = new JetspeedDeployUtils();
+        JetspeedDeployUtils.ZipObject zipObject;
+        boolean success;
         try
         {
             String portletApplicationName = contextName;
             tempFile = File.createTempFile(portletApplicationName, "");
             tempFile.deleteOnExit();
+            
+            tempPsmlDir = new File(tempFile.getParentFile().getPath()+"/psml");            
+            success = tempPsmlDir.mkdir();
+            
 
             jin = new JarFile(inputName);
             jout = new JarOutputStream(new FileOutputStream(tempFile));
@@ -137,6 +151,27 @@
                         System.out.println("Found META-INF/context.xml");
                         contextXml = parseXml(source);
                     }
+                    else if(target.startsWith("psml"))
+                    {
+                        inputStream = jin.getInputStream(src);
+                        zipObject = utils.formatZipEntryName(src);                        
+                        if(src.isDirectory())
+                        {
+                            if(!zipObject.getName().equals("psml") && zipObject.getParents().length ==1){
+                                utils.createPath(tempPsmlDir.getPath(),zipObject.getParents());    
+                            }                            
+                        }else{
+                            utils.createPath(tempPsmlDir.getPath(),zipObject.getParents());
+                            destPath = utils.getFullPath(tempPsmlDir.getPath(),zipObject.getParents(),zipObject.getName()); 
+                            outputStream = new BufferedOutputStream(new FileOutputStream(destPath));
+                            while((len = inputStream.read(buffer)) >= 0)
+                            {
+                                outputStream.write(buffer, 0, len);
+                            }
+                            inputStream.close();
+                            outputStream.close();
+                        }                   
+                    }
                     else
                     {
                         if ( stripLoggers && target.endsWith(".jar") &&
@@ -209,7 +244,7 @@
             jin.close();
             jin = null;
             jout = null;
-
+            utils.importJetspeedObjects(tempPsmlDir.getPath());
             System.out.println("Creating war " + outputName + " ...");
             System.out.flush();
             // Now copy the new war to its destination
@@ -273,10 +308,15 @@
                     // ignore
                 }
             }
+            if (tempPsmlDir != null && tempPsmlDir.exists())
+            {
+                utils.deleteDirectory(tempPsmlDir);
+            }
             if (tempFile != null && tempFile.exists())
             {
                 tempFile.delete();
             }
+            
         }
     }
 

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeployUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeployUtils.java?rev=704947&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeployUtils.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeployUtils.java Wed Oct 15 09:09:18 2008
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.tools.deploy;
+
+import java.io.File;
+import java.security.PrivilegedAction;
+import java.util.Iterator;
+import java.util.zip.ZipEntry;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.exception.JetspeedException;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.Link;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.security.JSSubject;
+import org.apache.jetspeed.security.UserManager;
+
+/**
+ * @author vkumar <a href="vkumar@apache.org">Vivek Kumar</a>
+ */
+public class JetspeedDeployUtils
+{
+    PageManager pageManager = (PageManager) Jetspeed.getComponentManager().getComponent("org.apache.jetspeed.page.PageManager");
+    UserManager userManager = (UserManager) Jetspeed.getComponentManager().getComponent("org.apache.jetspeed.security.UserManager");
+    PageManager xmlPageManager = (PageManager) Jetspeed.getComponentManager().getComponent("org.apache.jetspeed.page.CastorPageManager");
+
+    class ZipObject
+    {
+        public ZipObject()
+        {
+        }
+
+        String parents[] = null;
+        String name;
+
+        /**
+         * @return the parents
+         */
+        public String[] getParents()
+        {
+            return parents;
+        }
+
+        /**
+         * @param parents
+         *            the parents to set
+         */
+        public void setParents(String[] parents)
+        {
+            this.parents = parents;
+        }
+
+        /**
+         * @return the name
+         */
+        public String getName()
+        {
+            return name;
+        }
+
+        /**
+         * @param name
+         *            the name to set
+         */
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+    }
+
+    public ZipObject formatZipEntryName(ZipEntry entry)
+    {
+        String tempName = null;
+        String tempPath[] = null;
+        ZipObject zipObj = this.new ZipObject();
+        tempPath = entry.getName().split("/");
+        if (tempPath.length >= 2)
+        {
+            tempName = tempPath[tempPath.length - 1];
+        }
+        else
+        {
+            tempName = tempPath[0];
+        }
+        zipObj.setName(tempName);
+        tempName = entry.getName();
+        tempPath = tempName.split("/");
+        if (tempPath.length == 2)
+        {
+            tempPath = (String[]) ArrayUtils.remove(tempPath, 0);
+            zipObj.setParents(tempPath);
+        }
+        else if (tempPath.length > 2)
+        {
+            tempPath = (String[]) ArrayUtils.remove(tempPath, 0);
+            tempPath = (String[]) ArrayUtils.remove(tempPath, tempPath.length - 1);
+            zipObj.setParents(tempPath);
+        }
+        else
+        {
+            zipObj.setParents(tempPath);
+        }
+        return zipObj;
+    }
+
+    public String getFullPath(String basePath, String paths[], String name)
+    {
+        String tempPath = "";
+        for (String path : paths)
+        {
+            tempPath = tempPath + "/" + path;
+        }
+        tempPath = basePath + tempPath + "/" + name;
+        return tempPath;
+    }
+
+    public void createPath(String basePath, String paths[])
+    {
+        String tempPath;
+        File tempFile;
+        if (paths.length >= 1)
+        {
+            tempPath = basePath + "/" + paths[0];
+            tempFile = new File(tempPath);
+            if (!tempFile.exists())
+            {
+                tempFile.mkdir();
+            }
+            for (int counter = 1; counter < paths.length; counter++)
+            {
+                tempPath = tempPath + "/" + paths[counter];
+                tempFile = new File(tempPath);
+                if (!tempFile.exists())
+                {
+                    tempFile.mkdir();
+                }
+            }
+        }
+    }
+
+    private Folder importFolders(Folder srcFolder, String destination, boolean root) throws JetspeedException
+    {
+        Folder dstFolder = null;
+        if (!root)
+        {
+            dstFolder = pageManager.copyFolder(srcFolder, destination);
+            pageManager.updateFolder(dstFolder);
+        }
+        String newPath = "";
+        Iterator pages = srcFolder.getPages().iterator();
+        while (pages.hasNext())
+        {
+            Page srcPage = (Page) pages.next();
+            newPath = destination + "/" + srcPage.getName();
+            Page dstPage = pageManager.copyPage(srcPage, newPath);
+            pageManager.updatePage(dstPage);
+        }
+        Iterator links = srcFolder.getLinks().iterator();
+        while (links.hasNext())
+        {
+            Link srcLink = (Link) links.next();
+            newPath = destination + "/" + srcLink.getName();
+            Link dstLink = pageManager.copyLink(srcLink, newPath);
+            pageManager.updateLink(dstLink);
+        }
+        Iterator folders = srcFolder.getFolders().iterator();
+        while (folders.hasNext())
+        {
+            Folder folder = (Folder) folders.next();
+            newPath = destination + "/" + folder.getName();
+            importFolders(folder, newPath, false);
+        }
+        return dstFolder;
+    }
+
+    public void importJetspeedObjects(String importPsmlFolder)
+    {
+        String powerUser = "admin";
+        try
+        {
+            JetspeedException pe = (JetspeedException) JSSubject.doAsPrivileged(userManager.getSubject(userManager.getUser(powerUser)), new PrivilegedAction()
+            {
+                public Object run()
+                {
+                    try
+                    {
+                        Folder srcFolder = xmlPageManager.getFolder("psml");
+                        importFolders(srcFolder, "/", true);
+                    }
+                    catch (Exception e)
+                    {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                    return null;
+                }
+            }, null);
+        }
+        catch (JetspeedException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    public boolean deleteDirectory(File path) {
+        if( path.exists() ) {
+          File[] files = path.listFiles();
+          for(int i=0; i<files.length; i++) {
+             if(files[i].isDirectory()) {
+               deleteDirectory(files[i]);
+             }
+             else {
+               files[i].delete();
+             }
+          }
+        }
+        return( path.delete() );
+      }
+
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeployUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-deploy-tools/src/main/java/org/apache/jetspeed/tools/deploy/JetspeedDeployUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org