[seam-commits] Seam SVN: r10402 - in trunk/examples/wiki: src/main/org/jboss/seam/wiki/admin and 8 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 14 11:51:10 EDT 2009


Author: christian.bauer at jboss.com
Date: 2009-04-14 11:51:10 -0400 (Tue, 14 Apr 2009)
New Revision: 10402

Added:
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiFaceletViewHandler.java
Modified:
   trunk/examples/wiki/src/etc/WEB-INF/faces-config.xml
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/admin/WikiHttpSessionManager.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/CommentHome.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHistory.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHome.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/WikiNodeDAO.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalWikiFile.hbm.xml
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiFile.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/listener/NestedSetFlushEventListener.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiURLRenderer.java
   trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/helloWorld/templates/helloWorld.xhtml
   trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/helloWorld/themes/default/css/helloWorld.css
   trunk/examples/wiki/view/themes/sfwkorg/template.xhtml
Log:
Various minor bugfixes and improvements on wiki

Modified: trunk/examples/wiki/src/etc/WEB-INF/faces-config.xml
===================================================================
--- trunk/examples/wiki/src/etc/WEB-INF/faces-config.xml	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/etc/WEB-INF/faces-config.xml	2009-04-14 15:51:10 UTC (rev 10402)
@@ -5,7 +5,12 @@
         <locale-config>
             <default-locale>en</default-locale>
         </locale-config>
+
+        <view-handler>org.jboss.seam.wiki.core.ui.WikiFaceletViewHandler</view-handler>
+        <!-- Better exception handling overrides
         <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
+        -->
+
     </application>
 
     <!-- Needed because WikiFormattedTextHandler instantiates these, asking the JSF infrastructure -->

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/admin/WikiHttpSessionManager.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/admin/WikiHttpSessionManager.java	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/admin/WikiHttpSessionManager.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -211,9 +211,11 @@
                 )
             );
         }
+
+        Collections.sort(onlineMembers);
     }
 
-    public static class OnlineUser {
+    public static class OnlineUser implements Comparable {
         private User user;
         private long lastAccessedTime;
 
@@ -241,6 +243,12 @@
         public String getIdleTime() {
             return WikiUtil.getTimeDifferenceToCurrent(WikiUtil.toDate(lastAccessedTime));
         }
+
+        public int compareTo(Object o) {
+            OnlineUser other = (OnlineUser) o;
+            if (getLastAccessedTime() > other.getLastAccessedTime()) return -1;
+            return (getLastAccessedTime() == other.getLastAccessedTime() ? 0 : 1);
+        }
     }
 
 }

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/CommentHome.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/CommentHome.java	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/CommentHome.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -144,6 +144,10 @@
                 getEntityManager().flush();
             }
 
+            getLog().debug("updating last comment aggregation for: " + documentHome.getInstance());
+            getWikiNodeDAO().updateWikiDocumentLastComment(documentHome.getInstance());
+            getEntityManager().flush();
+
             Events.instance().raiseEvent("Comment.persisted");
             endConversation();
             WikiRedirect.instance()
@@ -174,7 +178,12 @@
 
             remove();
             getEntityManager().clear();
-            Events.instance().raiseEvent("Comment.removed");
+
+            getLog().debug("updating last comment aggregation for: " + documentHome.getInstance());
+            getWikiNodeDAO().updateWikiDocumentLastComment(documentHome.getInstance());
+            getEntityManager().flush();
+
+            getEntityManager().clear();
             Events.instance().raiseEvent("Comment.commentListRefresh");
         }
 

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHistory.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHistory.java	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHistory.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -197,7 +197,7 @@
         displayedHistoricalFile = null;
 
         if (historicalFileId == null) return;
-        selectedHistoricalFile = wikiNodeDAO.findHistoricalFile(getCurrentFile().getHistoricalEntityName(), historicalFileId);
+        selectedHistoricalFile = wikiNodeDAO.findHistoricalDocumentAndDetach(getCurrentFile().getHistoricalEntityName(), historicalFileId);
         if (selectedHistoricalFile == null) {
             statusMessages.addFromResourceBundleOrDefault(
                 ERROR,

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHome.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHome.java	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHome.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -25,6 +25,7 @@
 import org.jboss.seam.wiki.core.template.WikiDocumentEditorDefaults;
 import org.jboss.seam.wiki.core.wikitext.editor.WikiTextEditor;
 import org.jboss.seam.wiki.preferences.Preferences;
+import org.jboss.seam.wiki.util.WikiUtil;
 
 import static org.jboss.seam.international.StatusMessage.Severity.INFO;
 
@@ -150,7 +151,9 @@
         if (documentHistory != null && documentHistory.getSelectedHistoricalFile() != null) {
             getLog().debug("rolling back to revision: " + documentHistory.getSelectedHistoricalFile().getRevision());
             // TODO: Avoid cast, make history polymorphic
-            doc.rollback((WikiDocument)documentHistory.getSelectedHistoricalFile());
+            WikiDocument oldRevision = (WikiDocument)documentHistory.getSelectedHistoricalFile();
+            doc.rollback(oldRevision);
+            doc.setWikiname(WikiUtil.convertToWikiName(doc.getName()));
         }
 
         isOnSiteFeed = feedDAO.isOnSiteFeed(doc);
@@ -430,11 +433,4 @@
         return textEditor;
     }
 
-    /* TODO: Performance Optimizations */
-
-    @org.jboss.seam.annotations.Observer(value = {"Comment.persisted", "Comment.removed"}, create = false)
-    public void updateLastComment() {
-        getWikiNodeDAO().updateWikiDocumentLastComment(getInstance());
-        getEntityManager().flush();
-    }
 }

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/WikiNodeDAO.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/WikiNodeDAO.java	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/WikiNodeDAO.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -484,11 +484,22 @@
         return null;
     }
 
+    // TODO: This method is a mess...
     // Returns a detached object
-    public WikiFile findHistoricalFile(String entityName, Long historyId) {
-        WikiFile historicalFile = (WikiFile)getSession(true).get(entityName, historyId);
-        getSession(true).evict(historicalFile);
-        return historicalFile;
+    public WikiDocument findHistoricalDocumentAndDetach(String entityName, Long historyId) {
+        // Initialize bytecode-enhanced fields with 'fetch all properties'!
+        log.debug("fetching WikiFile historical revision with id: " + historyId + " and initializing all properties");
+        WikiDocument historicalFile = (WikiDocument)
+                getSession(true).createQuery("select f from " + entityName + " f fetch all properties where f.historicalFileId = :id")
+                .setParameter("id", historyId)
+                .uniqueResult();
+        if (historicalFile != null) {
+            historicalFile.getContent(); // TODO: the fetch all properties doesn't work for some reason..
+            getSession(true).evict(historicalFile);
+            return historicalFile;
+        } else {
+            return null;
+        }
     }
 
     public List<WikiFile> findHistoricalFiles(WikiFile file) {

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalWikiFile.hbm.xml
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalWikiFile.hbm.xml	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalWikiFile.hbm.xml	2009-04-14 15:51:10 UTC (rev 10402)
@@ -25,7 +25,7 @@
         <property name="lastModifiedByUsername" column="LAST_MODIFIED_BY_USERNAME" not-null="false"/>
 
         <!-- Optional WikiFile subclass properties -->
-        <property name="content" column="CONTENT" length="32767"/>
+        <property name="content" column="CONTENT" length="32767" lazy="true"/>
 
     </class>
 

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiFile.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiFile.java	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiFile.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -84,7 +84,6 @@
 
     public void rollback(WikiFile revision) {
         this.name = revision.name;
-        this.wikiname = revision.wikiname;
     }
 
     public List<String> getTagsAsList() {

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/listener/NestedSetFlushEventListener.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/listener/NestedSetFlushEventListener.java	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/listener/NestedSetFlushEventListener.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -80,7 +80,7 @@
 
         if (eventSource.getActionQueue().areInsertionsOrDeletionsQueued()) {
             try {
-                log.debug("######################### trying to obtain exclusive lock for " + LOCK_TIMEOUT_SECONDS +
+                log.debug("trying to obtain exclusive lock for " + LOCK_TIMEOUT_SECONDS +
                           " seconds before performing database modifications during flush");
                 if (lock.tryLock(LOCK_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
                     log.debug("successfully obtained lock, executing flush");

Added: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiFaceletViewHandler.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiFaceletViewHandler.java	                        (rev 0)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiFaceletViewHandler.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -0,0 +1,73 @@
+package org.jboss.seam.wiki.core.ui;
+
+import com.sun.facelets.FaceletViewHandler;
+import com.sun.facelets.util.DevTools;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author Christian Bauer
+ */
+public class WikiFaceletViewHandler extends FaceletViewHandler {
+
+    protected boolean developmentMode; // Private in superclass, hurray!
+
+    public WikiFaceletViewHandler(ViewHandler viewHandler) {
+        super(viewHandler);
+    }
+
+    @Override
+    protected void initialize(FacesContext context) {
+        super.initialize(context);
+
+        ExternalContext external = context.getExternalContext();
+        String param = external.getInitParameter(PARAM_DEVELOPMENT);
+        this.developmentMode = "true".equals(param);
+    }
+
+    @Override
+    protected void handleRenderException(FacesContext context, Exception e)
+            throws IOException, ELException, FacesException {
+
+        Object resp = context.getExternalContext().getResponse();
+
+/* This is what we don't like: log and rethrow! Makes Facelets nasty in production use...
+        // always log
+        if (log.isLoggable(Level.SEVERE)) {
+            UIViewRoot root = context.getViewRoot();
+            StringBuffer sb = new StringBuffer(64);
+            sb.append("Error Rendering View");
+            if (root != null) {
+                sb.append('[');
+                sb.append(root.getViewId());
+                sb.append(']');
+            }
+            log.log(Level.SEVERE, sb.toString(), e);
+        }
+*/
+        // handle dev response
+        if (this.developmentMode && !context.getResponseComplete()
+                && resp instanceof HttpServletResponse) {
+            HttpServletResponse httpResp = (HttpServletResponse) resp;
+            httpResp.reset();
+            httpResp.setContentType("text/html; charset=UTF-8");
+            Writer w = httpResp.getWriter();
+            DevTools.debugHtml(w, context, e);
+            w.flush();
+            context.responseComplete();
+        } else if (e instanceof RuntimeException) {
+            throw (RuntimeException) e;
+        } else if (e instanceof IOException) {
+            throw (IOException) e;
+        } else {
+            throw new FacesException(e.getMessage(), e);
+        }
+    }
+}

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiURLRenderer.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiURLRenderer.java	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiURLRenderer.java	2009-04-14 15:51:10 UTC (rev 10402)
@@ -7,11 +7,9 @@
 package org.jboss.seam.wiki.core.ui;
 
 import org.jboss.seam.Component;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.AutoCreate;
+import org.jboss.seam.annotations.*;
 import org.jboss.seam.ScopeType;
+import org.jboss.seam.log.Log;
 import org.jboss.seam.wiki.util.WikiUtil;
 import org.jboss.seam.wiki.core.action.prefs.WikiPreferences;
 import org.jboss.seam.wiki.core.model.WikiNode;
@@ -35,6 +33,9 @@
 @AutoCreate
 public class WikiURLRenderer implements Serializable {
 
+    @Logger
+    Log log;
+
     @In
     String contextPath;
 
@@ -138,8 +139,11 @@
     }
 
     public String renderPermURL(WikiNode node, boolean usePrefsPath) {
+        log.debug("rendering perm URL for node: " + node);
         if (node == null || node.getId() == null) return "";
-        return (usePrefsPath ? prefs.getBaseUrl() : contextPath) + "/" + node.getPermURL(prefs.getPermlinkSuffix());
+        String url = (usePrefsPath ? prefs.getBaseUrl() : contextPath) + "/" + node.getPermURL(prefs.getPermlinkSuffix());
+        log.debug("rendered URL: " + url);
+        return url;
     }
 
     public String renderWikiURL(WikiNode node) {
@@ -147,8 +151,11 @@
     }
 
     public String renderWikiURL(WikiNode node, boolean usePrefsPath) {
+        log.debug("rendering wiki URL for node: " + node);
         if (node == null || node.getId() == null) return "";
-        return (usePrefsPath ? prefs.getBaseUrl() : contextPath) + "/" + node.getWikiURL();
+        String url = (usePrefsPath ? prefs.getBaseUrl() : contextPath) + "/" + node.getWikiURL();
+        log.debug("rendered URL: " + url);
+        return url;
     }
 
     // TODO: We need more methods here, rendering year/month/day/tag/etc. on WikiURL (not perm url)

Modified: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/helloWorld/templates/helloWorld.xhtml
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/helloWorld/templates/helloWorld.xhtml	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/helloWorld/templates/helloWorld.xhtml	2009-04-14 15:51:10 UTC (rev 10402)
@@ -63,6 +63,6 @@
 
     </h:panelGrid>
 
-    <wiki:loadStyle src="#{currentMacro.requestCSSPath}/anotherOne.css"/>
+    <wiki:loadStyle src="#{currentMacro.requestStylesheetPath}/anotherOne.css"/>
 
 </wiki:plugin>
\ No newline at end of file

Modified: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/helloWorld/themes/default/css/helloWorld.css
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/helloWorld/themes/default/css/helloWorld.css	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/helloWorld/themes/default/css/helloWorld.css	2009-04-14 15:51:10 UTC (rev 10402)
@@ -1,5 +1,5 @@
 .justABox {
-    background: #fff url(#{currentMacro.requestImagePath}/background.gif) 0 0 repeat-x;
+    background: #fff url(#{request.contextPath}#{currentPluginModule.imagePath}/background.gif) 0 0 repeat-x;
     border: 1px solid green;
     margin: 20px;
 }

Modified: trunk/examples/wiki/view/themes/sfwkorg/template.xhtml
===================================================================
--- trunk/examples/wiki/view/themes/sfwkorg/template.xhtml	2009-04-14 15:47:38 UTC (rev 10401)
+++ trunk/examples/wiki/view/themes/sfwkorg/template.xhtml	2009-04-14 15:51:10 UTC (rev 10402)
@@ -401,7 +401,7 @@
 </div>
 
 <div id="footer" class="undecoratedLink">
-  <p> &#169; Copyright 2008, Red Hat Middleware, LLC. All rights reserved. JBoss and Seam are registered trademarks
+  <p> &#169; Copyright 2009, Red Hat Middleware, LLC. All rights reserved. JBoss and Seam are registered trademarks
       and servicemarks of <a href="http://www.redhat.com/">Red Hat, Inc</a>.
       [<a href="http://www.redhat.com/legal/privacy_statement.html">Privacy Policy</a>]</p>
 </div>




More information about the seam-commits mailing list