You are viewing a plain text version of this content. The canonical link for it is here.
Posted to photark-commits@incubator.apache.org by lr...@apache.org on 2009/09/13 22:58:52 UTC

svn commit: r814430 - in /incubator/photark/trunk: photark-embedded/src/main/resources/ photark/src/main/java/org/apache/photark/services/album/filesystem/ photark/src/main/java/org/apache/photark/services/gallery/ photark/src/main/java/org/apache/phot...

Author: lresende
Date: Sun Sep 13 22:58:52 2009
New Revision: 814430

URL: http://svn.apache.org/viewvc?rev=814430&view=rev
Log:
Adding initial ui that list all albums from a gallery

Added:
    incubator/photark/trunk/photark-embedded/src/main/resources/album.html
      - copied, changed from r814429, incubator/photark/trunk/photark-embedded/src/main/resources/gallery.html
    incubator/photark/trunk/photark-embedded/src/main/resources/photo-album.composite
      - copied, changed from r814429, incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite
Modified:
    incubator/photark/trunk/photark-embedded/src/main/resources/gallery.html
    incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite
    incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/filesystem/AlbumImpl.java
    incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java
    incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/GalleryImpl.java

Copied: incubator/photark/trunk/photark-embedded/src/main/resources/album.html (from r814429, incubator/photark/trunk/photark-embedded/src/main/resources/gallery.html)
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-embedded/src/main/resources/album.html?p2=incubator/photark/trunk/photark-embedded/src/main/resources/album.html&p1=incubator/photark/trunk/photark-embedded/src/main/resources/gallery.html&r1=814429&r2=814430&rev=814430&view=diff
==============================================================================
    (empty)

Modified: incubator/photark/trunk/photark-embedded/src/main/resources/gallery.html
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-embedded/src/main/resources/gallery.html?rev=814430&r1=814429&r2=814430&view=diff
==============================================================================
--- incubator/photark/trunk/photark-embedded/src/main/resources/gallery.html (original)
+++ incubator/photark/trunk/photark-embedded/src/main/resources/gallery.html Sun Sep 13 22:58:52 2009
@@ -26,67 +26,68 @@
 <script language="JavaScript">
 
 	//@Reference
-	var album = new tuscany.sca.Reference("album");
+	var gallery = new tuscany.sca.Reference("gallery");
 
-	var albumItems;
-	var currPos = 0;
+	var galleryName;
+	var galleryAlbums;
 
-	function album_getResponse(items, exception) {
+	function gallery_getAlbumsResponse(albums, exception) {
 		if(exception) {
 			alert(exception.msg);
 			return;
 		}
-		albumItems = items;
-		showAlbum();
+		galleryAlbums = albums;
+
+		if(galleryAlbums.length > 0) {
+		    showGallery();
+		}
 	}
 
-   function showImage(pos) {
-   	var img = document.createElement("img");
-	img.onload = function(evt) {
-		document.getElementById("albumImage").src = this.src;
-        document.getElementById("albumImage").width=this.width;
-        document.getElementById("albumImage").height=this.height;
-    }
-    img.src = albumItems[pos];
-    return false;
-   }
-
-   function showAlbum() {
-      if(albumItems.length > 0) {
-		showImage(currPos);
-	  }
-   }
-
-   function goNext() {
-   	 if(currPos < albumItems.length) {
-	 	currPos++;
-		showImage(currPos);
-	 }
-   }
-
-   function goPrevious() {
-   	if(currPos > 0) {
-		currPos--;
-		showImage(currPos);
+	function showGallery() {
+		var table=document.getElementById('tableGallery');
+		var lastRow = table.rows.length;
+		for(i=0; i<galleryAlbums.length; i++) {
+			   var row=table.insertRow(lastRow++);
+			   var column=row.insertCell(0);
+
+			   var albumName = galleryAlbums[i].name;
+			   var albumCover = gallery.getAlbumCover(albumName);
+			   var img_src = albumCover;
+			   var html = "<img src=" + "gallery/" + albumName + "/" + img_src + " class=\"slideImage\" height=25% width=25% ondragstart=\"return false\" onselectstart=\"return false\" oncontextmenu=\"return false\" galleryimg=\"no\" usemap=\"#imagemap\" alt=\"\"/>";
+			   column.innerHTML = html;
+
+			   row = table.insertRow(lastRow++);
+			   column = row.insertCell(0)
+			   column.innerHTML = albumName;
+
+			   row = table.insertRow(lastRow++);
+			   column = row.insertCell(0)
+			   column.innerHTML = "<img src=\"space.gif\" class=\"slideImage\" width=\"10\" height=\"10\" ondragstart=\"return false\" onselectstart=\"return false\" oncontextmenu=\"return false\" galleryimg=\"no\" usemap=\"#imagemap\" alt=\"\">";
+		   }
+
 	}
-   }
+
+	function showImage(pos) {
+	   	var img = document.createElement("img");
+		img.onload = function(evt) {
+			document.getElementById("albumImage").src = this.src;
+	        document.getElementById("albumImage").width=this.width;
+	        document.getElementById("albumImage").height=this.height;
+	    }
+	    img.src = albumItems[pos];
+	    return false;
+	   }
+		
+
 
 	function init() {
 		try {
-			album.getPictures(album_getResponse);
+			gallery.getAlbums(gallery_getAlbumsResponse);
 		} catch(exception) {
 			alert(e);
 		}
 	}
 
-
-	index_off= new Image(31,31); index_off.src = "index.gif";
-    index_on = new Image(31,31); index_on.src = "index_on.gif";
-    next_off = new Image(31,31); next_off.src = "next.gif";
-	next_on  = new Image(31,31); next_on.src = "next_on.gif";
-	prev_off = new Image(31,31); prev_off.src = "prev.gif";
-	prev_on  = new Image(31,31); prev_on.src = "prev_on.gif";
-
 </script>
 
 </head>
@@ -97,39 +98,9 @@
 <br>
 <br>
   <div id="gallery">
-	<div id="album">
-		<!--img id="albumImage" border="0" src=""-->
-	</div>
-	<br>
+     <center>
+     <table id="tableGallery" style="width:720px;" border="0" cellspacing="0" cellpadding="1"/>
+     </center>
   </div>
-
-  <center>
-
-  <table style="height:54px;" cellspacing="0" cellpadding="0" border="0">
-     <tr>
-     	<td valign="middle">
-     	   <!-- Navigation Header -->
-		   <table style="width:100%;" cellspacing="0" cellpadding="0" border="0">
-             <tr>
-             	<!-- <td style="width:31px;"><a href="javascript:showAlbum()" onmouseover="document.index.src=index_on.src" onmouseout="document.index.src=index_off.src"><img src="index.gif" width="31" height="31" border="0" title="Index page" name="index" alt=""></a></td> -->
-                <td style="width:31px;"><a href="javascript:goPrevious()" onmouseover="document.previous.src=prev_on.src" onmouseout="document.previous.src=prev_off.src"><img src="prev.gif" width="31" height="31" border="0" title="Previous image" name="previous" alt=""></a></td>
-                <td style="width:31px;"><a href="javascript:goNext()" onmouseover="document.next.src=next_on.src" onmouseout="document.next.src=next_off.src"><img src="next.gif" width="31" height="31" border="0" title="Next image" name="next" alt=""></a></td>
-                <!-- <td style="width:31px;"><a href="javascript:void(0)" onmouseover="show_over();" onmouseout="show_out();" onmousedown="show_down();" ondblclick="change_delay();"><img src="show_slide.gif" width="31" height="31" border="0" title="Start/Stop slideshow - DoubleClick to change speed" name="show" alt=""></a></td> -->
-             </tr>
-		   </table>
-		</td>
-	</tr>
-  </table>
-
-  <table style="width:720px;" border="0" cellspacing="0" cellpadding="0">
-    <tr>
-     	<td align="center"> <!-- Image without original -->
-        <img id="albumImage" src="space.gif" class="slideImage" width="720" height="540" ondragstart="return false" onselectstart="return false" oncontextmenu="return false" galleryimg="no" usemap="#imagemap" alt="">
-		</td>
-    </tr>
-  </table>
-
-  </center>
-
 </body>
 </html>

Copied: incubator/photark/trunk/photark-embedded/src/main/resources/photo-album.composite (from r814429, incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite)
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-embedded/src/main/resources/photo-album.composite?p2=incubator/photark/trunk/photark-embedded/src/main/resources/photo-album.composite&p1=incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite&r1=814429&r2=814430&rev=814430&view=diff
==============================================================================
--- incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite (original)
+++ incubator/photark/trunk/photark-embedded/src/main/resources/photo-album.composite Sun Sep 13 22:58:52 2009
@@ -20,17 +20,17 @@
 <composite	xmlns="http://www.osoa.org/xmlns/sca/1.0"
 		xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
 		xmlns:photark="http://org.apache.photoark"
-		targetNamespace="http://org.apache.photoark"
-		name="photo-gallery">
+		targetNamespace="http://org.apache.photoark/album"
+		name="photo-album">
 		
     <component name="Gallery">
         <tuscany:implementation.widget location="gallery.html"/>
         <service name="Widget">
         	<tuscany:binding.http uri="/gallery"/>
-        </service>
-		<reference name="album" target="AlbumAgregator/Album">
+        </service>        
+		<reference name="gallery" target="Gallery">
 		 	<tuscany:binding.jsonrpc/>
-		 </reference>
+		 </reference>		 
     </component>
     
     <component name="AlbumAgregator">
@@ -53,6 +53,10 @@
 		<property name="album">boston</property>
 	</component> 
 
+    <component name="Gallery">
+   		<implementation.java class="org.apache.photark.services.gallery.filesystem.GalleryImpl"/>
+   		<property name="name">gallery</property>
+    </component>
 	
 	<component name="GalleryPictures">
 		<tuscany:implementation.resource location="gallery"/>

Modified: incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite?rev=814430&r1=814429&r2=814430&view=diff
==============================================================================
--- incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite (original)
+++ incubator/photark/trunk/photark-embedded/src/main/resources/photo-gallery.composite Sun Sep 13 22:58:52 2009
@@ -27,32 +27,19 @@
         <tuscany:implementation.widget location="gallery.html"/>
         <service name="Widget">
         	<tuscany:binding.http uri="/gallery"/>
-        </service>
-		<reference name="album" target="AlbumAgregator/Album">
+        </service>        
+		<reference name="gallery" target="GalleryComponentService">
 		 	<tuscany:binding.jsonrpc/>
-		 </reference>
+		 </reference>		 
     </component>
     
-    <component name="AlbumAgregator">
-        <implementation.java class="org.apache.photark.services.album.AlbumAgregator"/>
-		<service name="Album">
-			<tuscany:binding.jsonrpc/>
+    <component name="GalleryComponentService">
+   		<implementation.java class="org.apache.photark.services.gallery.filesystem.GalleryImpl"/>
+   		<property name="name">gallery</property>
+   		<service name="Gallery">
+   			<tuscany:binding.jsonrpc/>
    		</service>
-		<reference name="album" target="Album"/>
-        <reference name="albumFeed">
-           <tuscany:binding.atom uri="http://api.flickr.com/services/feeds/photoset.gne?set=72157601530865813&amp;nsid=36437931@N00&amp;lang=en-us"/>
-        </reference>
-        <reference name="albumPicassa">
-           <tuscany:binding.gdata uri="http://picasaweb.google.com/data/feed/api/user/haibotuscany/album/flowers" serviceType="lh2" username="haibotuscany@gmail.com" password="gsocgsocgsoc"/>
-        </reference>        
     </component>
-    
-	<component name="Album">
-		<implementation.java class="org.apache.photark.services.album.filesystem.AlbumImpl"/> 
-		<property name="gallery">gallery</property>
-		<property name="album">boston</property>
-	</component> 
-
 	
 	<component name="GalleryPictures">
 		<tuscany:implementation.resource location="gallery"/>

Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/filesystem/AlbumImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/filesystem/AlbumImpl.java?rev=814430&r1=814429&r2=814430&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/filesystem/AlbumImpl.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/filesystem/AlbumImpl.java Sun Sep 13 22:58:52 2009
@@ -31,26 +31,27 @@
 
 
 public class AlbumImpl implements Album {
-    private String gallery;
     private String name;
     private String location;
+    
+    private boolean initialized;
     private List<String> pictures = new ArrayList<String>();
 
     @Init
     public void init() {
         try {
-            URL albumURL = this.getClass().getClassLoader().getResource(getLocation());
+            /*
+            URL albumURL = this.getClass().getClassLoader().getResource(name);
             if(albumURL == null) {
                 // Accomodate for J2EE classpath that starts in WEB-INF\classes
                 albumURL = this.getClass().getClassLoader().getResource("../../" + getLocation());
-            }
+            }*/
 
-            if(albumURL != null) {
-                File album = new File(albumURL.toURI());
+            if(location != null) {
+                File album = new File(location);
                 if (album.isDirectory() && album.exists()) {
                     String[] listPictures = album.list(new ImageFilter(".jpg"));
                     for(String image : listPictures) {
-                        image = getLocation() + image;
                         pictures.add(image);
                     }
                 }
@@ -60,12 +61,6 @@
             e.printStackTrace();
         }
     }
-
-    @Property
-    public void setGallery(String gallery) {
-        this.gallery = gallery;
-        this.location = null;
-    }
     
     public String getName() {
         return name;
@@ -77,24 +72,24 @@
         this.location = null;
     }
 
-    
-    public String[] getPictures() {
-        String[] pictureArray = new String[pictures.size()];
-        pictures.toArray(pictureArray);
-        return pictureArray;
-    }
-
     public String getLocation() {
-        if (location == null) {
-            location = gallery + "/" + name + "/";
-        }
         return location;
     }
     
+    @Property
     public void setLocation(String location) {
         this.location = location;
     }
     
+    public String[] getPictures() {
+        if( ! initialized) {
+            init();
+        }
+        String[] pictureArray = new String[pictures.size()];
+        pictures.toArray(pictureArray);
+        return pictureArray;
+    }
+
     /**
      * Inner fileFilter class
      */

Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java?rev=814430&r1=814429&r2=814430&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java Sun Sep 13 22:58:52 2009
@@ -32,4 +32,8 @@
     
     Album[] getAlbums();
     
+    String getAlbumCover(String albumName);
+    
+    String[] getAlbumPictures(String albumName);
+    
 }

Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/GalleryImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/GalleryImpl.java?rev=814430&r1=814429&r2=814430&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/GalleryImpl.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/GalleryImpl.java Sun Sep 13 22:58:52 2009
@@ -47,10 +47,10 @@
     @Init
     public void init() {
         try {
-            URL galleryURL = this.getClass().getClassLoader().getResource(getLocation());
+            URL galleryURL = this.getClass().getClassLoader().getResource(name);
             if(galleryURL == null) {
                 // Accomodate for J2EE classpath that starts in WEB-INF\classes
-                galleryURL = this.getClass().getClassLoader().getResource("../../" + getLocation());
+                galleryURL = this.getClass().getClassLoader().getResource("../../" + name);
             }
 
             if(galleryURL != null) {
@@ -84,7 +84,6 @@
     @Property
     public void setName(String name) {
         this.name = name;
-        this.location = null;
     }
 
     public void addAlbum(Album album) {
@@ -100,11 +99,42 @@
         albums.toArray(albumArray);
         return albumArray;
     }
+    
+    public String getAlbumCover(String albumName) {
+        Album albumLookup = getAlbum(albumName);
+        
+        if (albumLookup != null) {
+            return albumLookup.getPictures()[0];
+        } else {
+            //FIXME: return proper not found exception
+            return null;             
+        }
+    }
+    
+    public String[] getAlbumPictures(String albumName) {
+        Album albumLookup = getAlbum(albumName);
+        
+        if (albumLookup != null) {
+            return albumLookup.getPictures();
+        } else {
+            //FIXME: return proper not found exception
+            return new String[]{};             
+        }
+    }
+    
+    private Album getAlbum(String albumName) {
+        Album albumLookup = null;
+        for(Album album : albums) {
+            if(album.getName().equalsIgnoreCase(albumName)) {
+                albumLookup = album;
+                break;
+            }
+        }
+        
+        return albumLookup;
+    }
 
     private String getLocation() {
-        if(location == null) {
-            location = name;
-        }
         return location;
     }
 }