[seam-commits] Seam SVN: r8687 - in trunk/examples/wiki: src/main/org/jboss/seam/wiki/core/ui and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Aug 14 07:01:37 EDT 2008


Author: christian.bauer at jboss.com
Date: 2008-08-14 07:01:37 -0400 (Thu, 14 Aug 2008)
New Revision: 8687

Added:
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/Unarchiver.java
Modified:
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/metamodel/ProfilePluginModule.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiRedirect.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/upload/importers/ZipImporter.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/WikiUtil.java
   trunk/examples/wiki/view/userProfile_d.xhtml
Log:
Minor fixes

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/metamodel/ProfilePluginModule.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/metamodel/ProfilePluginModule.java	2008-08-13 22:04:48 UTC (rev 8686)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/metamodel/ProfilePluginModule.java	2008-08-14 11:01:37 UTC (rev 8687)
@@ -44,7 +44,7 @@
     }
 
     public int compareTo(Object o) {
-        int result = new Integer(((ProfilePluginModule)o).getPriority()).compareTo(this.getPriority());
+        int result = new Integer(this.getPriority()).compareTo( ((ProfilePluginModule)(o)).getPriority() );
         return result == 0
             ? this.getKey().compareTo( ((ProfilePluginModule)o).getKey() )
             : result;

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiRedirect.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiRedirect.java	2008-08-13 22:04:48 UTC (rev 8686)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiRedirect.java	2008-08-14 11:01:37 UTC (rev 8687)
@@ -11,6 +11,7 @@
 import org.jboss.seam.annotations.Logger;
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.Component;
+import org.jboss.seam.core.Manager;
 import org.jboss.seam.log.Log;
 import org.jboss.seam.faces.RedirectException;
 import org.jboss.seam.wiki.core.model.WikiDocument;
@@ -88,7 +89,8 @@
                 : urlRenderer.renderURL(getWikiDocument());
 
         // TODO: Fragile?
-        if (propagateConversation)  url = url + "?cid=" + org.jboss.seam.core.Conversation.instance().getId();
+        String conversationIdParam = Manager.instance().getConversationIdParameter();
+        if (propagateConversation)  url = url + "?"+conversationIdParam+"=" + org.jboss.seam.core.Conversation.instance().getId();
 
         if (getFragment() != null) url = url + "#" + fragment;
         

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/upload/importers/ZipImporter.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/upload/importers/ZipImporter.java	2008-08-13 22:04:48 UTC (rev 8686)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/upload/importers/ZipImporter.java	2008-08-14 11:01:37 UTC (rev 8687)
@@ -30,6 +30,11 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
+/**
+ * TODO: Delegate code to util.Unarchiver
+ *
+ * @author Christian Bauer
+ */
 @Name("zipImporter")
 @UploadImporter(
         handledMimeTypes = {"application/zip", "application/java-archive"},

Added: trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/Unarchiver.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/Unarchiver.java	                        (rev 0)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/Unarchiver.java	2008-08-14 11:01:37 UTC (rev 8687)
@@ -0,0 +1,89 @@
+package org.jboss.seam.wiki.util;
+
+import org.jboss.seam.wiki.core.model.WikiUpload;
+import org.jboss.seam.log.Log;
+import org.jboss.seam.log.Logging;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipEntry;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * @author Christian Bauer
+ */
+public class Unarchiver {
+
+    Log log = Logging.getLog(Unarchiver.class);
+
+    protected Handler handler;
+
+    public Unarchiver(Handler handler) {
+        this.handler = handler;
+    }
+
+    public void extract(WikiUpload zipFile) {
+        if (zipFile == null) {
+            throw new IllegalArgumentException("Archive must not be null");
+        }
+
+        if (zipFile.getData().length == 0) return;
+
+        Map<String, Object> newObjects = new HashMap<String, Object>();
+
+        ByteArrayInputStream byteStream = null;
+        ZipInputStream zipInputStream = null;
+        try {
+            byteStream = new ByteArrayInputStream(zipFile.getData());
+            zipInputStream = new ZipInputStream(new BufferedInputStream(byteStream));
+
+            int bufferSize = 1024;
+            ZipEntry ze;
+            ByteArrayOutputStream baos;
+            byte[] buffer = new byte[bufferSize];
+            byte[] uncompressedBytes;
+            int bytesRead;
+
+            while ((ze = zipInputStream.getNextEntry()) != null) {
+                log.trace("extracting zip entry: " + ze.getName());
+
+                if (!handler.beforeUncompress(zipFile, ze)) continue;
+
+                baos = new ByteArrayOutputStream();
+                while ((bytesRead = zipInputStream.read(buffer, 0, bufferSize)) > 0) {
+                    baos.write(buffer, 0, bytesRead);
+                }
+                baos.close();
+                uncompressedBytes = baos.toByteArray();
+
+                Object newObject = handler.createNewObject(zipFile, ze, uncompressedBytes);
+                if (newObject != null) {
+                    newObjects.put(ze.getName(), newObject);
+                }
+
+                zipInputStream.closeEntry();
+            }
+
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        } finally {
+            try {
+                if (zipInputStream != null) zipInputStream.close();
+                if (byteStream != null) byteStream.close();
+            } catch (Exception e) {
+                e.printStackTrace(System.err);
+            }
+        }
+
+        handler.handleNewObjects(zipFile, newObjects);
+    }
+
+    public interface Handler<T> {
+        public boolean beforeUncompress(WikiUpload zipFile, ZipEntry zipEntry);
+        public T createNewObject(WikiUpload zipFile, ZipEntry zipEntry, byte[] uncompressedBytes);
+        public abstract void handleNewObjects(WikiUpload zipFile, Map<String, T> newObjects);
+    }
+}

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/WikiUtil.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/WikiUtil.java	2008-08-13 22:04:48 UTC (rev 8686)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/WikiUtil.java	2008-08-14 11:01:37 UTC (rev 8687)
@@ -376,4 +376,22 @@
         return msgId.toString();
     }
 
+    public static String convertUnderscoreToCamelCase(String s) {
+        StringBuilder sb = new StringBuilder();
+        boolean uppercaseNextChar = false;
+        for (char c : s.toCharArray()) {
+            if (c == '_') {
+                uppercaseNextChar = true;
+            } else {
+                if (uppercaseNextChar) {
+                    sb.append(Character.toString(c).toUpperCase());
+                    uppercaseNextChar = false;
+                } else {
+                    sb.append(c);
+                }
+            }
+        }
+        return sb.toString();
+    }
+
 }

Modified: trunk/examples/wiki/view/userProfile_d.xhtml
===================================================================
--- trunk/examples/wiki/view/userProfile_d.xhtml	2008-08-13 22:04:48 UTC (rev 8686)
+++ trunk/examples/wiki/view/userProfile_d.xhtml	2008-08-14 11:01:37 UTC (rev 8687)
@@ -33,6 +33,7 @@
     <s:div>
         <c:forEach var="pm" items="#{pluginRegistry.profilePluginModulesAsList}">
             <ui:include src="/#{pm.plugin.getPackageDefaultTemplatePath(pm.template)}"/>
+            <br/>
         </c:forEach>
     </s:div>
 




More information about the seam-commits mailing list