geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r354719 - in /geronimo/trunk/applications/console-standard/src: java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java webapp/WEB-INF/view/repository/normal.jsp
Date Wed, 07 Dec 2005 05:28:47 GMT
Author: ammulder
Date: Tue Dec  6 21:28:42 2005
New Revision: 354719

URL: http://svn.apache.org/viewcvs?rev=354719&view=rev
Log:
Fix repository portlet  GERONIMO-1262  (Thanks Joe!)

Modified:
    geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java
    geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/repository/normal.jsp

Modified: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java?rev=354719&r1=354718&r2=354719&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java
(original)
+++ geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java
Tue Dec  6 21:28:42 2005
@@ -17,17 +17,20 @@
 
 package org.apache.geronimo.console.repository;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.portlet.PortletFileUpload;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.console.BasePortlet;
+import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.repository.FileWriteMonitor;
+import org.apache.geronimo.kernel.repository.ListableRepository;
+import org.apache.geronimo.kernel.repository.WriteableRepository;
 
-import javax.management.ObjectName;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletConfig;
@@ -37,18 +40,19 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
-
-import org.apache.geronimo.console.BasePortlet;
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.fileupload.FileUploadException;
-import org.apache.commons.fileupload.disk.DiskFileItemFactory;
-import org.apache.commons.fileupload.portlet.PortletFileUpload;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.KernelRegistry;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
 
 public class RepositoryViewPortlet extends BasePortlet {
 
-    private static final String REPO_OBJ_NAME = "geronimo.server:name=Repository,J2EEServer=geronimo,J2EEApplication=null,j2eeType=GBean,J2EEModule=org/apache/geronimo/System";
+    private final static Log log = LogFactory.getLog(RepositoryViewPortlet.class);
 
     private Kernel kernel;
 
@@ -58,8 +62,6 @@
 
     private PortletRequestDispatcher helpView;
 
-    private URL rootURL;
-
     public void init(PortletConfig portletConfig) throws PortletException {
         super.init(portletConfig);
         kernel = KernelRegistry.getSingleKernel();
@@ -68,65 +70,65 @@
                 .getRequestDispatcher("/WEB-INF/view/repository/normal.jsp");
         helpView = ctx
                 .getRequestDispatcher("/WEB-INF/view/repository/help.jsp");
-
-        URI uri = null;
-
-        try {
-            ObjectName reponame = new ObjectName(REPO_OBJ_NAME);
-            uri = new URI(".");
-            rootURL = (URL) kernel.invoke(reponame, "getURL",
-                    new Object[] {uri}, new String[] {"java.net.URI"});
-            uri = new URI(rootURL.toString());
-            rootURL.getFile();
-        } catch (Exception e) {
-            throw new PortletException(e);
-        }
-
-        if (!uri.getScheme().equals("file")) {
-            throw new PortletException("unsupported scheme: repositoryURL = "
-                    + rootURL.toString());
-        }
     }
 
     public void processAction(ActionRequest actionRequest,
             ActionResponse actionResponse) throws PortletException, IOException {
         try {
 
-            File rootDir = new File(rootURL.getFile() + File.separatorChar
-                    + "upload" + File.separatorChar + "jars");
 
-            if (!rootDir.exists()) {
-                rootDir.mkdirs();
-            }
 
-            PortletFileUpload uploader = new PortletFileUpload(
-                    new DiskFileItemFactory(10240, rootDir));
+            List list = new ArrayList();
+            WriteableRepository repo = PortletManager.getWritableRepositories(actionRequest)[0];
 
             File uploadFile = null;
+            File file = null;
+            String name = null;
+            String basename = null;
+            String fileType = null;
+            String artifact = null;
+            String version = null;
+            String group = null;
 
+            PortletFileUpload uploader = new PortletFileUpload(new DiskFileItemFactory());
             try {
-
                 List items = uploader.parseRequest(actionRequest);
                 for (Iterator i = items.iterator(); i.hasNext();) {
                     FileItem item = (FileItem) i.next();
                     if (!item.isFormField()) {
                         String fieldName = item.getFieldName().trim();
-                        String name = item.getName().trim();
-                        File file;
+                        name = item.getName().trim();
 
                         if (name.length() == 0) {
                             file = null;
                         } else {
-                            // Firefox sends basename, IE sends full path
-                            int index = name.lastIndexOf('\\');
-                            if (index != -1) {
-                                name = name.substring(index + 1);
+                            // IE sends full path while Firefox sends just basename
+                            // in the case of "FullName" we may be able to infer the group
+                            // Note, we can't use File.separatorChar because the file separator
+                            // is dependent upon the client and not the server.
+                            String fileChar = "\\";
+                            int fileNameIndex = name.lastIndexOf(fileChar);
+                            if (fileNameIndex == -1) {
+                               fileChar = "/";
+                               fileNameIndex = name.lastIndexOf(fileChar);
+                            }
+                            if (fileNameIndex != -1) {
+                               basename = name.substring(fileNameIndex + 1);
+                            }
+                            else {
+                               basename = name;
                             }
-                            file = new File(rootDir, name);
+
+                            // Create the temporary file to be used for import to the server
+                            file = File.createTempFile("geronimo-import", "");
+                            file.deleteOnExit();
+                            log.debug("Writing repository import file to "+file.getAbsolutePath());
                         }
+
                         if ("local".equals(fieldName)) {
                             uploadFile = file;
                         }
+
                         if (file != null) {
                             try {
                                 item.write(file);
@@ -134,10 +136,40 @@
                                 throw new PortletException(e);
                             }
                         }
+                    // This is not the file itself, but one of the form fields for the URI
+                    } else {
+                        String fieldName = item.getFieldName().trim();
+                        if ("group".equals(fieldName)) {
+                            group = item.getString().trim();
+                        } else if ("artifact".equals(fieldName)) {
+                            artifact = item.getString().trim();
+                        } else if ("version".equals(fieldName)) {
+                            version = item.getString().trim();
+                        } else if ("fileType".equals(fieldName)) {
+                            fileType = item.getString().trim();
+                        }
                     }
                 }
+
+                String uri = group + "/" + artifact + "/" + version + "/" + fileType;
+
+                repo.copyToRepository(file, new URI(uri), new FileWriteMonitor() {
+                    public void writeStarted(String fileDescription) {
+                        System.out.print("Copying into repository "+fileDescription+"...");
+                        System.out.flush();
+                    }
+
+                    public void writeProgress(int bytes) {
+                    }
+
+                    public void writeComplete(int bytes) {
+                        System.out.println(" Finished.");
+                    }
+                });
             } catch (FileUploadException e) {
                 throw new PortletException(e);
+            } catch (URISyntaxException e) {
+                throw new IOException("Unable to save to repository URI: "+e.getMessage());
             }
         } catch (PortletException e) {
             throw e;
@@ -152,13 +184,24 @@
         }
 
         try {
-            File f = new File(new URI(rootURL.toString()));
-            List ls = listing(f, f.getCanonicalPath());
-            Collections.sort(ls);
-
-            request.setAttribute("org.apache.geronimo.console.repo.root",
-                    rootURL.toString());
-            request.setAttribute("org.apache.geronimo.console.repo.list", ls);
+            List list = new ArrayList();
+            ListableRepository[] repos = PortletManager.getListableRepositories(request);
+            for (int i = 0; i < repos.length; i++) {
+                ListableRepository repo = repos[i];
+                try {
+                    final URI[] uris = repo.listURIs();
+                    for (int j = 0; j < uris.length; j++) {
+                        String fileName = uris[j].toString();
+                        list.add(fileName);
+                    }
+                } catch (URISyntaxException e) {
+                    e.printStackTrace();
+                }
+            }
+            Collections.sort(list);
+
+            request.setAttribute("org.apache.geronimo.console.repo.list", list);
+
         } catch (Exception e) {
             throw new PortletException(e);
         }

Modified: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/repository/normal.jsp
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/repository/normal.jsp?rev=354719&r1=354718&r2=354719&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/repository/normal.jsp
(original)
+++ geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/repository/normal.jsp
Tue Dec  6 21:28:42 2005
@@ -2,7 +2,6 @@
 <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
 <portlet:defineObjects/>
 
-<c:set var="rooturl" value="${requestScope['org.apache.geronimo.console.repo.root']}"/>
 <c:set var="reslist" value="${requestScope['org.apache.geronimo.console.repo.list']}"/>
 
 <style type="text/css">  
@@ -17,41 +16,111 @@
 </style>  
 
 <script language="JavaScript">
+function <portlet:namespace/>validate() {
+   if (! (document.<portlet:namespace/>fileSelect.local.value 
+      && document.<portlet:namespace/>fileSelect.group.value 
+      && document.<portlet:namespace/>fileSelect.artifact.value 
+      && document.<portlet:namespace/>fileSelect.version.value 
+      && document.<portlet:namespace/>fileSelect.fileType.value))
+   {
+      alert("File, Group, Artifact, Version, and Type are all required fields");
+      return false;
+   }
+}
+
+function <portlet:namespace/>parse(localFile) {
+   // Check for windows file delim
+   fileChar = "\\";
+   fileNameIndex = localFile.lastIndexOf(fileChar);
+   if (fileNameIndex == -1) {
+      // if not found check for *nix delim
+      fileChar = "/";
+      fileNameIndex = localFile.lastIndexOf(fileChar);
+   }
+
+   if (fileNameIndex != -1) {
+      basename = localFile.substring(fileNameIndex + 1);
+
+      prefix = localFile.substring(0 , fileNameIndex );
+
+      groupIndex = prefix.lastIndexOf(fileChar);
+      if (groupIndex != -1) {
+          group = prefix.substring(groupIndex + 1 );
+          document.<portlet:namespace/>fileSelect.group.value = group;        
+      }
+   }
+   else {
+      basename = localFile;
+   }
+
+   // Attempt to get the artifact and type from the basename
+   typeIndex = basename.lastIndexOf(".");
+   if (typeIndex != -1) {
+       fileType = basename.substring(typeIndex + 1);
+       document.<portlet:namespace/>fileSelect.fileType.value = fileType;
+
+       artifact = basename.substring(0 , typeIndex ); 
+
+       versionIndex = artifact.lastIndexOf("-");
+       if (versionIndex != -1) {
+           version = artifact.substring(versionIndex + 1); 
+           document.<portlet:namespace/>fileSelect.version.value = version;
+
+           artifact = artifact.substring(0 , versionIndex );
+           document.<portlet:namespace/>fileSelect.artifact.value = artifact;
+       }
+       else {
+          version = artifact = "";
+       }
+   }
+   else {
+      fileType = "";
+   }
+}
 
-state1 = false;
-
-function toggle1() {
-	state1 = !state1;
-	document.getElementById("first").className = state1 ? "Shown" : "Hidden";
-} 
 </script>
 
 <table width="100%">
-<th>root URL: <c:out value="${rooturl}"/></th>
 <tr>
- <center><td>
- <form enctype="multipart/form-data" method="POST" action="<portlet:actionURL><portlet:param
name="action" value="deploy"/></portlet:actionURL>">
- <table> 
-  <th align="center"><center>Add File to Repository</center></th>
-  <tr>
-
+  <td align="center">
+  <form onsubmit="return <portlet:namespace/>validate();" enctype="multipart/form-data"
name="<portlet:namespace/>fileSelect" method="POST" action="<portlet:actionURL><portlet:param
name="action" value="deploy"/></portlet:actionURL>">
+  <table>
+    <tr>
+      <th colspan="2">Add Archive to Repository</th>
+    </tr>
+    <tr>
+      <td>File</td>
+      <td><input name="local" onchange="<portlet:namespace/>parse(value);"
type="file">&nbsp;&nbsp;&nbsp;</td>
+    </tr>
+    <tr>
+      <td>Group:</td>
+      <td><input type="text" name="group" value="${group}"/></td>
+    </tr>
+    <tr>
+      <td>Artifact:</td>
+      <td><input type="text" name="artifact" value="${artifact}"/></td>
+    </tr>
     <tr>
-   <td>File</td><td><input type="file" name="local">&nbsp;&nbsp;&nbsp;
  All uploaded files are placed in the 'uploaded' directory.</td>
-  </tr>  
- </table> 
- 
+      <td>Version:</td>
+      <td><input type="text" name="version" value="${version}"/></td>
+    </tr>
+    <tr>
+      <td>Type:</td>
+      <td><input type="text" name="fileType" value="${fileType}"/></td>
+    </tr>
+    <tr><td colspan="2"><font size="-2">&nbsp;</font></td></tr>
+    <tr>
+      <td colspan="2" align="center"><input type="submit" value="Install" /></td>
+    </tr>
+  </table>
+  </form>
   </td>
-  <tr>
-    <center><td><input type="submit" value="Install" /></td></center>
-  </tr>
-  <tr><td>&nbsp;</td></tr>
-  <tr><td>&nbsp;</td></tr>
-  </center>
 </tr>
- </form>
+</table>
+
+<b>Current Repository Entries</b>
+<ul>
 <c:forEach items="${reslist}" var="res">
-<tr><td><c:out value="${res}"/></td></tr>
+<li><c:out value="${res}"/></li>
 </c:forEach>
-<tr><td>&nbsp;</td></tr>
-<tr><td>&nbsp;</td></tr>
-</table>
+</ul>
\ No newline at end of file



Mime
View raw message