[richfaces-svn-commits] JBoss Rich Faces SVN: r13477 - in trunk/test-applications/realworld2/web/src/main: java/org/richfaces/realworld/ui and 4 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Apr 9 11:58:30 EDT 2009


Author: amarkhel
Date: 2009-04-09 11:58:30 -0400 (Thu, 09 Apr 2009)
New Revision: 13477

Removed:
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/tags/RealworldCommandButtonRenderer.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/RealworldException.java
Modified:
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/DirectLinkHelper.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ImageLoader.java
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ActionMapperTagHandler.java
   trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/button.xhtml
   trunk/test-applications/realworld2/web/src/main/webapp/includes/search/result/userResult.xhtml
   trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/avatar.xhtml
Log:
Refactoring

Deleted: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/tags/RealworldCommandButtonRenderer.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/tags/RealworldCommandButtonRenderer.java	2009-04-09 15:58:20 UTC (rev 13476)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/tags/RealworldCommandButtonRenderer.java	2009-04-09 15:58:30 UTC (rev 13477)
@@ -1,65 +0,0 @@
-/**
- * 
- */
-package org.richfaces.realworld.tags;
-
-import java.io.IOException;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.ajax4jsf.renderkit.AjaxCommandRendererBase;
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-
-
-/**
- * @author Andrey Markavtsov
- *
- */
-//TODO nick - remove this
-public class RealworldCommandButtonRenderer extends AjaxCommandRendererBase {
-	
-	@Override
-	public void encodeBegin(FacesContext context, UIComponent component)
-			throws IOException {
-		Object id = component.getClientId(context);
-		Object style = component.getAttributes().get("style");
-		Object value = component.getAttributes().get("value");
-		
-		ResponseWriter writer = context.getResponseWriter();
-		writer.startElement(HTML.DIV_ELEM, component);
-			writer.writeAttribute(HTML.id_ATTRIBUTE, id, null);
-			writer.writeAttribute(HTML.class_ATTRIBUTE, "realworldButton", null);
-			writer.writeAttribute(HTML.style_ATTRIBUTE, style, null);
-			writer.writeAttribute(HTML.onclick_ATTRIBUTE, getOnClick(context, component), null);
-			
-		writer.startElement(HTML.IMG_ELEMENT, component);
-			writer.writeAttribute(HTML.src_ATTRIBUTE, "img/shell/button.png", null);
-			writer.writeAttribute(HTML.width_ATTRIBUTE, "103", null);
-			writer.writeAttribute(HTML.height_ATTRIBUTE, "28", null);
-			writer.writeAttribute(HTML.alt_ATTRIBUTE, "", null);
-			writer.writeAttribute(HTML.border_ATTRIBUTE, "0", null);
-		writer.endElement(HTML.IMG_ELEMENT);
-		
-		writer.startElement(HTML.DIV_ELEM, component);
-			writer.writeText(value, null);
-		writer.endElement(HTML.DIV_ELEM);
-		
-		writer.startElement(HTML.IMG_ELEMENT, component);
-			writer.writeAttribute(HTML.src_ATTRIBUTE, "img/shell/spacer.gif", null);
-			writer.writeAttribute(HTML.width_ATTRIBUTE, "103", null);
-			writer.writeAttribute(HTML.height_ATTRIBUTE, "28", null);
-			writer.writeAttribute(HTML.alt_ATTRIBUTE, "", null);
-			writer.writeAttribute(HTML.border_ATTRIBUTE, "0", null);
-		writer.endElement(HTML.IMG_ELEMENT);	
-		
-		writer.endElement(HTML.DIV_ELEM);
-	}
-	
-	@Override
-	protected Class<? extends UIComponent> getComponentClass() {
-		return org.ajax4jsf.component.UIAjaxCommandButton.class;
-	}
-
-}

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/DirectLinkHelper.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/DirectLinkHelper.java	2009-04-09 15:58:20 UTC (rev 13476)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/DirectLinkHelper.java	2009-04-09 15:58:30 UTC (rev 13477)
@@ -14,7 +14,6 @@
 import org.jboss.seam.security.Identity;
 import org.richfaces.realworld.domain.Image;
 import org.richfaces.realworld.service.Constants;
-import org.richfaces.realworld.util.RealworldException;
 
 @Name("directLink")
 @Scope(ScopeType.EVENT)
@@ -30,17 +29,25 @@
 	@In Credentials credentials;
 	
 	public void paintImage(OutputStream out, Object data)
-			throws IOException, RealworldException {
+			throws IOException {
 		Long id = Long.valueOf(data.toString());
 		Image im = em.find(Image.class, id);
-		if(im == null || im.getAlbum() == null || im.getAlbum().getShelf() == null){
+		if(isImageRecentlyRemoved(im)){
 			imageLoader.paintImage(out, Constants.DEFAULT_PICTURE);
 			return;
 		}
-		if(im.getAlbum().getShelf().isShared() || (identity.hasRole(Constants.ADMIN_ROLE) && im.getAlbum().getOwner().getLogin().equals(credentials.getUsername()))){
+		if(isImageSharedOrBelongsToUser(im)){
 			imageLoader.paintImage(out, im.getFullPath());
 		}else{
 			return;
 		}
 	}
+
+	private boolean isImageSharedOrBelongsToUser(Image im) {
+		return im.getAlbum().getShelf().isShared() || (identity.hasRole(Constants.ADMIN_ROLE) && im.getAlbum().getOwner().getLogin().equals(credentials.getUsername()));
+	}
+
+	private boolean isImageRecentlyRemoved(Image im) {
+		return im == null || im.getAlbum() == null || im.getAlbum().getShelf() == null;
+	}
 }
\ No newline at end of file

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ImageLoader.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ImageLoader.java	2009-04-09 15:58:20 UTC (rev 13476)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/ImageLoader.java	2009-04-09 15:58:30 UTC (rev 13477)
@@ -44,18 +44,22 @@
     @In FileManager fileManager;
 
     public void paintImage(OutputStream out, Object data) throws IOException {
-        
     	if (null == data) {
             return;
-        } 
-        
-        File imageResource = null;
-       
-        if(data.toString().endsWith(Constants.UPLOAD)){
-        	imageResource = fileManager.getFileByAbsolutePath(data.toString());
-        }else{
-        	imageResource = fileManager.getFileByPath(data.toString());
         }
+        File imageResource = fileManager.getFileByAbsolutePath(data.toString());
+        paintImageToBrowser(out, imageResource);
+    }
+    
+    public void paintAvatarImage(OutputStream out, Object data) throws IOException {
+    	if (null == data) {
+            return;
+        }
+    	File imageResource = fileManager.getFileByPath(data.toString());
+        paintImageToBrowser(out, imageResource);
+    }
+    
+    public void paintImageToBrowser(OutputStream out, File imageResource) throws IOException {
         
         if (imageResource != null && imageResource.exists()) {
               	

Modified: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ActionMapperTagHandler.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ActionMapperTagHandler.java	2009-04-09 15:58:20 UTC (rev 13476)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ActionMapperTagHandler.java	2009-04-09 15:58:30 UTC (rev 13477)
@@ -197,5 +197,4 @@
 			nextHandler.apply(ctx, parent);
 		}
 	}
-
-}
+}
\ No newline at end of file

Deleted: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/RealworldException.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/RealworldException.java	2009-04-09 15:58:20 UTC (rev 13476)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/RealworldException.java	2009-04-09 15:58:30 UTC (rev 13477)
@@ -1,11 +0,0 @@
-package org.richfaces.realworld.util;
-
-public class RealworldException extends Exception {
-
-	/** The serialVersionUID */
-	private static final long serialVersionUID = -5437284703541833879L;
-
-	public RealworldException(String message) {
-		super(message);
-	}
-}

Modified: trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/button.xhtml
===================================================================
--- trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/button.xhtml	2009-04-09 15:58:20 UTC (rev 13476)
+++ trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/button.xhtml	2009-04-09 15:58:30 UTC (rev 13477)
@@ -1,5 +1,3 @@
-<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
-                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <ui:composition xmlns="http://www.w3.org/1999/xhtml"
 	xmlns:s="http://jboss.com/products/seam/taglib"
 	xmlns:c="http://java.sun.com/jstl/core"

Modified: trunk/test-applications/realworld2/web/src/main/webapp/includes/search/result/userResult.xhtml
===================================================================
--- trunk/test-applications/realworld2/web/src/main/webapp/includes/search/result/userResult.xhtml	2009-04-09 15:58:20 UTC (rev 13476)
+++ trunk/test-applications/realworld2/web/src/main/webapp/includes/search/result/userResult.xhtml	2009-04-09 15:58:30 UTC (rev 13477)
@@ -10,7 +10,7 @@
 			<h:panelGrid cellpadding="0">
 				<h:panelGroup>
 						<a4j:commandLink reRender="mainArea" actionListener="#{controller.showUser(searchedUser)}">
-							<a4j:mediaOutput rendered="#{searchedUser.hasAvatar}" element="img" createContent="#{imageLoader.paintImage}"
+							<a4j:mediaOutput rendered="#{searchedUser.hasAvatar}" element="img" createContent="#{imageLoader.paintAvatarImage}"
 										styleClass="avatar"
 										value="/#{searchedUser.login}/avatar.jpg" />
 							<h:graphicImage rendered="#{!searchedUser.hasAvatar and searchedUser.sex.key =='1' }" value="/img/shell/avatar_default.png" width="80" height="80" alt="" style="border:none"/>

Modified: trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/avatar.xhtml
===================================================================
(Binary files differ)




More information about the richfaces-svn-commits mailing list