Index: photark-flickr/src/test/java/org/apache/photark/album/flickr/FlickrSubscriptionTestCase.java
===================================================================
--- photark-flickr/src/test/java/org/apache/photark/album/flickr/FlickrSubscriptionTestCase.java	(revision 1059763)
+++ photark-flickr/src/test/java/org/apache/photark/album/flickr/FlickrSubscriptionTestCase.java	(working copy)
@@ -23,7 +23,7 @@
 import org.apache.tuscany.sca.data.collection.Entry;
 import org.junit.BeforeClass;
 import org.junit.Test;
-
+ // <user password="aaa" roles="photark-admin" username="aaa"/>
 public class FlickrSubscriptionTestCase {
     private static final String SUBSCRIPTION_URL = "http://api.flickr.com/services/feeds/photos_public.gne?id=24662369@N07&lang=en-us&format=atom";
     private static FlickrPhotoStream photoStream;
Index: photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrPhotoStream.java
===================================================================
--- photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrPhotoStream.java	(revision 1059763)
+++ photark-flickr/src/main/java/org/apache/photark/album/flickr/FlickrPhotoStream.java	(working copy)
@@ -132,6 +132,7 @@
         image.setId(id.substring(id.lastIndexOf("/") + 1));
         image.setTitle(entry.getTitle());
         image.setLocation(entry.getEnclosureLinkResolvedHref().toString());
+        image.setName(id.substring(id.lastIndexOf("/") + 1));
 
         return image;
     }
Index: photark-ui/src/main/webapp/gallery.html
===================================================================
--- photark-ui/src/main/webapp/gallery.html	(revision 1059763)
+++ photark-ui/src/main/webapp/gallery.html	(working copy)
@@ -47,6 +47,10 @@
          <table id='tableGallery' style="margin-left:auto; margin-right:auto;width:720px;" border="0"
                 cellspacing="0" cellpadding="1">
          </table>
+         <h1>Remote Albums</h1>
+         <table id='remoteTableGallery' style="margin-left:auto; margin-right:auto;width:720px;" border="0"
+                cellspacing="0" cellpadding="1">
+         </table>
     </div>
     
     <div id="search" style="display:none;visibility:hidden;">
Index: photark-ui/src/main/webapp/js/constants.js
===================================================================
--- photark-ui/src/main/webapp/js/constants.js	(revision 1059763)
+++ photark-ui/src/main/webapp/js/constants.js	(working copy)
@@ -28,8 +28,11 @@
 photark.constants.contextRoot = "/photark/";
 photark.constants.adminContextRoot = "/photark/admin/";
 
-
+//photark.constants.FlickerAlbumSubscription = photark.constants.contextRoot + "FlickerAlbumSubscription?smd";
+photark.constants.RemoteAlbumSubscription = photark.constants.contextRoot + "RemoteAlbumSubscriptionManager?smd";
+//photark.constants.PicasaAlbumSubscription = photark.constants.contextRoot + "PicasaAlbumSubscription?smd";
 photark.constants.GalleryServiceEndpoint = photark.constants.contextRoot + "GalleryService?smd";
+photark.constants.RemoteGalleryServiceEndpoint = photark.constants.contextRoot + "JCRRemoteGallery?smd";
 photark.constants.SearchServiceEndpoint = photark.constants.contextRoot + "SearchService?smd";
 photark.constants.AccessManagerServiceEndpoint = photark.constants.contextRoot + "AccessManagerService?smd";
 
Index: photark-ui/src/main/webapp/js/gallery.js
===================================================================
--- photark-ui/src/main/webapp/js/gallery.js	(revision 1059763)
+++ photark-ui/src/main/webapp/js/gallery.js	(working copy)
@@ -31,15 +31,24 @@
 var show_slide_slow_on  = new Image(31,31); show_slide_slow_on.src = "images/show_slide_slow_on.gif";
 
 var gallery;
+var remoteGallery;
 var searchService;
 var galleryName;
+
 var galleryAlbums;
+var remoteGalleryAlbums;
+
 var albumTags;
 var albumCovers = new Array();
+var remoteAlbumCovers = new Array();
+
 var albumName;
 var albumItems;
 var albumPos = 0;
 var pos = 0;
+var rpos = 0;
+var remoteFlag = 0;
+
 var slideShowSpeed=0;
 var timer;
 var userId;
@@ -81,11 +90,16 @@
 function initServices(){
   	searchService = new dojo.rpc.JsonService( photark.constants.SearchServiceEndpoint );
     gallery = new dojo.rpc.JsonService( photark.constants.GalleryServiceEndpoint );
+    remoteGallery = new dojo.rpc.JsonService(photark.constants.RemoteGalleryServiceEndpoint);
+
 }
 
 function initGallery() {
     try {
         gallery.getAlbumsToUser(SECURITY_TOKEN).addCallback(gallery_getAlbumsResponse);
+       remoteGallery.getAlbumsToUser(SECURITY_TOKEN,"remote").addCallback(remote_gallery_getAlbumsResponse);
+
+
     } catch(exception) {
         alert(exception);
         // logout();
@@ -117,6 +131,22 @@
 
 }
 
+function remote_gallery_getAlbumsResponse(albums, exception) {
+
+    if(exception) {
+       // alert(exception.msg);
+       // return;
+         logout();
+    }
+    remoteGalleryAlbums = albums;
+
+    for(i=0; i< remoteGalleryAlbums.length; i++)
+    {
+       //gallery.getAlbumCover(galleryAlbums[i].name).addCallback(gallery_getAlbumCoverResponse);
+         remoteGallery.getAlbumCoverToUser(remoteGalleryAlbums[i].name,SECURITY_TOKEN,"remote").addCallback(remote_gallery_getAlbumCoverResponse);
+    }
+}
+
 function gallery_getAlbumsResponse(albums, exception) {
     if(exception) {
        // alert(exception.msg);
@@ -133,6 +163,21 @@
 }
 
 
+function remote_gallery_getAlbumCoverResponse(cover, exception) {
+    if(exception){
+//        alert(exception.msg);
+//        return;
+         logout();
+    }
+    remoteAlbumCovers[rpos] = cover;
+    rpos += 1;
+    if(remoteAlbumCovers.length == remoteGalleryAlbums.length)
+    {
+        initializeRemoteGallery();
+        displayRemoteGallery();
+    }
+}
+
 function gallery_getAlbumCoverResponse(cover, exception) {
     if(exception){
 //        alert(exception.msg);
@@ -218,6 +263,36 @@
 	 
 }
 
+function initializeRemoteGallery() {
+    var table=document.getElementById('remoteTableGallery');
+    var lastRow = table.rows.length;
+    for (i = 0; i < remoteGalleryAlbums.length; i++) {
+        var row = table.insertRow(lastRow++);
+        var column = row.insertCell(0);
+
+        if (remoteAlbumCovers[i] != null) {
+
+            var albumName = remoteGalleryAlbums[i].name;
+            var img = document.createElement("img");
+            img.src = remoteAlbumCovers[i];
+            var img_html = "<img src=" + img.src + " class=\"slideImage\" width=180px ondragstart=\"return false\" onselectstart=\"return false\" oncontextmenu=\"return false\" galleryimg=\"no\" usemap=\"#imagemap\" alt=\"\"/>";
+            var html = "<a href=\"javascript:initializeRemoteAlbum('" + albumName + "', null)\">" + img_html + "</a>";
+            column.innerHTML = html;
+
+            column = row.insertCell(1);
+            column.innerHTML = "<div style=\"width:500\">"+remoteGalleryAlbums[i].description+"</div>";
+
+            row = table.insertRow(lastRow++);
+            column = row.insertCell(0)
+            column.innerHTML = albumName;
+
+            row = table.insertRow(lastRow++);
+            column = row.insertCell(0)
+            column.innerHTML = "<img src=\"images/space.gif\" class=\"slideImage\" width=\"10\" height=\"10\" ondragstart=\"return false\" onselectstart=\"return false\" oncontextmenu=\"return false\" galleryimg=\"no\" usemap=\"#imagemap\" alt=\"\">";
+        }
+   }
+}
+
 function initializeGallery() {
     var table=document.getElementById('tableGallery');
     var lastRow = table.rows.length;
@@ -248,6 +323,13 @@
    }
 }
 
+function displayRemoteGallery() {
+    setVisibility('gallery',true);
+    setVisibility('album',false);
+    setVisibility('search',false);
+}
+
+
 function displayGallery() {
     setVisibility('gallery',true);
     setVisibility('album',false);
@@ -272,6 +354,18 @@
     }
 }
 
+function initializeRemoteAlbum(albumName,imageName) {
+    try {
+        this.albumName = albumName;
+   	   	albumImageToBeLoaded = imageName;
+   	   	albumTags = new Array();
+   	   	remoteGallery.getAlbumPicturesToUser(albumName,SECURITY_TOKEN,"remote").addCallback(gallery_getRemoteAlbumPicturesResponse);
+
+    } catch(exception) {
+        alert(e);
+    }
+}
+
 function loadTags(albumPos) {
 	var imageTags = albumTags[albumName + '/' + albumItems[albumPos]];
 	
@@ -388,6 +482,33 @@
     showAlbum();
 }
 
+function gallery_getRemoteAlbumPicturesResponse(items, exception) {
+    if(exception) {
+       // alert(exception.msg);
+        displayGallery();
+         logout();
+      //  return;
+    }
+    albumItems = items;
+    albumPos = 0;
+
+    if (albumImageToBeLoaded != null) {
+
+    	for (i = 0 ; i < items.length ; i++) {
+
+    		if (items[i] == albumImageToBeLoaded) {
+    			albumPos = i;
+    			albumImageToBeLoaded = null;
+
+    		}
+
+    	}
+
+    }
+
+    showRemoteAlbum();
+}
+
 function showAlbum() {
     if(albumItems.length > 0) {
         showImage(albumPos);
@@ -395,6 +516,13 @@
     displayAlbum();
 }
 
+function showRemoteAlbum() {
+    if(albumItems.length > 0) {
+        showRemoteImage(albumPos);
+    }
+    displayAlbum();
+}
+
 function displayAlbum() {
     setVisibility('gallery',false);
     setVisibility('album',true);
@@ -410,20 +538,44 @@
     }
     img.src = window.location.href + "gallery/"+ this.albumName +"/" + albumItems[albumPos];
     loadTags(albumPos);
+    remoteFlag = 0;
     return false;
 }
 
+function showRemoteImage(albumPos) {
+    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[albumPos];
+    remoteFlag = 1;
+    loadTags(albumPos);
+    return false;
+}
+
+
 function goNext() {
     if(albumPos < albumItems.length - 1) {
         albumPos++;
+        if(remoteFlag ==1) {
+        showRemoteImage(albumPos);
+        } else {
         showImage(albumPos);
+        }
     }
 }
 
 function goPrevious() {
     if(albumPos > 0) {
         albumPos--;
+        if(remoteFlag ==1) {
+        showRemoteImage(albumPos);
+        } else {
         showImage(albumPos);
+        }
+
     }
 }
 
Index: photark-webapp/src/main/webapp/WEB-INF/web.composite
===================================================================
--- photark-webapp/src/main/webapp/WEB-INF/web.composite	(revision 1059763)
+++ photark-webapp/src/main/webapp/WEB-INF/web.composite	(working copy)
@@ -83,6 +83,7 @@
 			<binding.sca name="local"/>
 		</reference> 
 		<reference name="accessmanager" target="AccessManager"/>
+
 	</component>
 	
     <!-- Component responsible for providing JCR Management Support -->
@@ -138,6 +139,34 @@
 			<binding.sca name="local"/>
 		</reference>	
 		
-	</component>    
+	</component>
+
+
+
+    <component name="RemoteAlbumSubscriptionManager">
+		<implementation.java class="org.apache.photark.jcr.album.subscription.AlbumSubscriptionManager"/>
+
+		<service name="RemoteAlbumSubscription">
+   			<interface.java interface="org.apache.photark.services.gallery.RemoteAlbumSubscription"/>
+   			<binding.sca name="local"/>
+   			<tuscany:binding.jsonrpc uri="/RemoteAlbumSubscriptionManager"/>
+   		</service>
+     <reference name="repositoryManager" target="RepositoryManager"/>
+     <reference name="jcrRemoteGallery" target="RemoteGallery"/>
+	</component>
+
+    <component name="RemoteGallery">
+   		<implementation.java class="org.apache.photark.jcr.services.JCRRemoteGalleryImpl"/>
+   		<property name="name">gallery</property>
+   		<service name="RemoteGallery">
+   			<interface.java interface="org.apache.photark.services.gallery.RemoteGallery"/>
+   			<binding.sca name="local"/>
+   			<tuscany:binding.jsonrpc uri="/JCRRemoteGallery"/>
+   		</service>
+   		<reference name="repositoryManager" target="RepositoryManager"/>
+   		<reference name="listeners" target="SearchService"/>
+   	    <reference name="accessmanager" target="AccessManager"/>
+    </component>
+    
 	
 </composite>
Index: photark-webapp/pom.xml
===================================================================
--- photark-webapp/pom.xml	(revision 1059763)
+++ photark-webapp/pom.xml	(working copy)
@@ -140,6 +140,18 @@
 			<scope>runtime</scope>
 		</dependency>
 
+        <dependency>
+           <groupId>org.apache.photark</groupId>
+           <artifactId>photark-picasa</artifactId>
+           <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+           <groupId>org.apache.photark</groupId>
+           <artifactId>photark-flickr</artifactId>
+           <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>
+
 		<!-- dependency>
 		   <groupId>org.dojotoolkit</groupId>
 		   <artifactId>dojo</artifactId>
Index: photark-jcr/src/main/java/org/apache/photark/jcr/album/subscription/AlbumSubscriptionManager.java
===================================================================
--- photark-jcr/src/main/java/org/apache/photark/jcr/album/subscription/AlbumSubscriptionManager.java	(revision 0)
+++ photark-jcr/src/main/java/org/apache/photark/jcr/album/subscription/AlbumSubscriptionManager.java	(revision 0)
@@ -0,0 +1,108 @@
+package org.apache.photark.jcr.album.subscription;
+
+import org.apache.photark.Image;
+import org.apache.photark.album.flickr.FlickrPhotoStream;
+import org.apache.photark.album.picasa.PicasaPhotoStream;
+import org.apache.photark.jcr.JCRRepositoryManager;
+import org.apache.photark.jcr.services.JCRAlbumImpl;
+import org.apache.photark.jcr.services.JCRGalleryImpl;
+import org.apache.photark.services.gallery.RemoteAlbumSubscription;
+import org.apache.photark.services.gallery.RemoteGallery;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Remotable;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+import org.apache.tuscany.sca.data.collection.Entry;
+
+
+import java.util.logging.Logger;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: subash
+ * Date: Jan 31, 2011
+ * Time: 2:11:15 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@Remotable
+@Scope("COMPOSITE")
+public class AlbumSubscriptionManager implements RemoteAlbumSubscription {
+
+    private static FlickrPhotoStream flickerPhotoStream;
+    private static PicasaPhotoStream picasaPhotoStream;
+    private JCRRepositoryManager repositoryManager;
+    private static final Logger logger = Logger.getLogger(AlbumSubscriptionManager.class.getName());
+    private RemoteGallery remoteGallery;
+
+
+    public AlbumSubscriptionManager() {
+
+    }
+
+    @Reference(name = "repositoryManager")
+    protected void setRepositoryManager(JCRRepositoryManager repositoryManager) {
+        this.repositoryManager = repositoryManager;
+    }
+
+    @Reference(name = "jcrRemoteGallery")
+    protected void setGallery(RemoteGallery remoteGallery) {
+        this.remoteGallery = remoteGallery;
+    }
+
+
+    public Entry<String, Image>[] addRemoteAlbum(String url, String alb, String albDesc, String type) {
+
+        if ((type != null) && (type.equals("Subscribe-Picasa"))) {
+            return getPicasaAlbumSubscriptionImages(url, alb, albDesc);
+        } else if ((type != null) && (type.equals("Subscribe-Flicker"))) {
+            return getFlickerAlbumSubscriptionImages(url, alb, albDesc);
+        } else {
+            return null;
+        }
+    }
+
+
+    private Entry<String, Image>[] getFlickerAlbumSubscriptionImages(String url, String albumName, String albumDesc) {
+
+        remoteGallery.addAlbum(albumName, "remote");
+        JCRAlbumImpl jcrAlbImpl = new JCRAlbumImpl(repositoryManager, albumName, "remote");
+        jcrAlbImpl.setDescription(albumDesc);
+        flickerPhotoStream = new FlickrPhotoStream(url);
+        Entry<String, Image>[] images = flickerPhotoStream.getAll();
+
+        for (Entry<String, Image> image : images) {
+            Image i = image.getData();
+            i.setType("remote");
+            System.out.println(">> ID       : " + i.getId());
+            System.out.println(">> Title    : " + i.getTitle());
+            System.out.println(">> Location : " + i.getLocation());
+            jcrAlbImpl.addPicture(i);
+
+        }
+
+        return images;
+    }
+
+    private Entry<String, Image>[] getPicasaAlbumSubscriptionImages(String url, String albumName, String albumDesc) {
+
+        remoteGallery.addAlbum(albumName, "remote");
+        JCRAlbumImpl jcrAlbImpl = new JCRAlbumImpl(repositoryManager, albumName, "remote");
+        jcrAlbImpl.setDescription(albumDesc);
+        picasaPhotoStream = new PicasaPhotoStream(url);
+        Entry<String, Image>[] images = picasaPhotoStream.getAll();
+        for (Entry<String, Image> image : images) {
+            Image i = image.getData();
+            i.setType("remote");
+            System.out.println(">> ID       : " + i.getId());
+            System.out.println(">> Title    : " + i.getTitle());
+            System.out.println(">> Location : " + i.getLocation());
+            jcrAlbImpl.addPicture(i);
+
+        }
+
+        return images;
+    }
+
+
+}
Index: photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageCollectionImpl.java
===================================================================
--- photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageCollectionImpl.java	(revision 1059763)
+++ photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageCollectionImpl.java	(working copy)
@@ -82,7 +82,7 @@
         InputStream inStream = null;
         try {
             Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
+            Node root = session.getRootNode().getNode("albums").getNode("local");
             Node albumNode = root.getNode(albumName);
             String image = stringArray[1];
             Node picNode = albumNode.getNode(image);
Index: photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java
===================================================================
--- photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java	(revision 1059763)
+++ photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java	(working copy)
@@ -57,6 +57,7 @@
     @Reference(name = "repositoryManager")
     protected void setRepositoryManager(JCRRepositoryManager repositoryManager) {
         this.repositoryManager = repositoryManager;
+        initBaseJCRStructure();
     }
 
 
@@ -69,6 +70,34 @@
         super(name);
     }
 
+           private void initBaseJCRStructure() {
+           try {
+               Session session = repositoryManager.getSession();
+               Node baseRoot = session.getRootNode();
+               Node rootNode;
+
+               if (!baseRoot.hasNode("albums")) {
+                   rootNode = baseRoot.addNode("albums");
+               } else {
+                   rootNode = baseRoot.getNode("albums");
+               }
+
+               if (!rootNode.hasNode("remote")) {
+                  rootNode.addNode("remote");
+               }
+
+               if (!rootNode.hasNode("local")) {
+                   rootNode.addNode("local");
+               }
+
+           } catch (RepositoryException e) {
+               e.printStackTrace();
+           } finally {
+
+           }
+
+       }
+
     @Init
     public void init() {
         logger.info("Initializing JCR Gallery");
@@ -119,7 +148,7 @@
     private void getAlbumsFromJcrRepository() {
         try {
             Session session = repositoryManager.getSession();
-            Node rootNode = session.getRootNode();
+            Node rootNode = session.getRootNode().getNode("albums").getNode("local");
             NodeIterator albumNodes = rootNode.getNodes();
             while (albumNodes.hasNext()) {
                 Node albumNode = albumNodes.nextNode();
@@ -142,7 +171,7 @@
     public void addAlbum(String albumName) {
         try {
             Session session = repositoryManager.getSession();
-            Node rootNode = session.getRootNode();
+            Node rootNode = session.getRootNode().getNode("albums").getNode("local");
             if (rootNode.hasNode(albumName)) {
                 logger.info("This album is already in gallery");
                 return;
@@ -165,7 +194,7 @@
     public boolean hasAlbum(String albumName) {
         try {
             Session session = repositoryManager.getSession();
-            Node rootNode = session.getRootNode();
+            Node rootNode = session.getRootNode().getNode("albums").getNode("local");
             if (rootNode.hasNode(albumName)) {
                 //   logger.info("This album is already in gallery");
                 return true;
@@ -181,7 +210,7 @@
     public void deleteAlbum(String albumName) {
         try {
             Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
+            Node root = session.getRootNode().getNode("albums").getNode("local");;
             if (root.hasNode(albumName)) {
                 Node albumNode = root.getNode(albumName);
                 Album album = JCRAlbumImpl.createAlbum(repositoryManager, albumName);
Index: photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java
===================================================================
--- photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java	(revision 1059763)
+++ photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java	(working copy)
@@ -44,26 +44,43 @@
 
     private String gallery;
     private String name;
+    private String type;
     private String location;
     private boolean initialized;
     private static Map<String, Album> albums = new HashMap<String, Album>();
 
-    public synchronized static Album createAlbum(JCRRepositoryManager repositoryManager, String name ) {
+    public synchronized static Album createAlbum(JCRRepositoryManager repositoryManager, String name) {
         if (!albums.containsKey(name)) {
-            albums.put(name, new JCRAlbumImpl(repositoryManager,name ));
+            albums.put(name, new JCRAlbumImpl(repositoryManager, name));
         }
         return albums.get(name);
     }
 
+    public synchronized static Album createAlbum(JCRRepositoryManager repositoryManager, String name, String type) { // Adhere to new structure
+
+        if (!albums.containsKey(name)) {
+            albums.put(name, new JCRAlbumImpl(repositoryManager, name, type));
+        }
+        return albums.get(name);
+    }
+
     public JCRAlbumImpl(JCRRepositoryManager repositoryManager, String name) {
         this.repositoryManager = repositoryManager;
         this.name = name;
+        this.type = "local";   // temporary
     }
 
+    public JCRAlbumImpl(JCRRepositoryManager repositoryManager, String name, String type) {
+
+        this.repositoryManager = repositoryManager;
+        this.name = name;
+        this.type = type;
+    }
+
     /**
      * Initialize the gallery service
-     *   - During initialization, check for local images and create a JCR album 
-     *     which is usefull for sample gallery shiped in the sample application.
+     * - During initialization, check for local images and create a JCR album
+     * which is usefull for sample gallery shiped in the sample application.
      */
     @Init
     public synchronized void init() {
@@ -82,7 +99,8 @@
                     if (album.isDirectory() && album.exists()) {
                         String[] listPictures = album.list(new ImageFilter(".jpg"));
                         if (listPictures != null && listPictures.length > 0) {
-                            Node albumNode = getAlbumNode(name);
+//                            Node albumNode = getAlbumNode(name);
+                            Node albumNode = getAlbumNode();              // this line added to adhere to new structure
                             for (String image : listPictures) {
                                 if (!albumNode.hasNode(image)) {
                                     Node picNode = albumNode.addNode(image);
@@ -122,6 +140,10 @@
         this.location = null;
     }
 
+    public String getType() {
+        return type;
+    }
+
     public String getName() {
         return name;
     }
@@ -133,22 +155,17 @@
     }
 
     public String getDescription() {
-        String description="";
+        String description = "";
         if (!initialized) {
             init();
         }
         try {
-            Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
-            Node albumNode = root.getNode(name);
+            Node albumNode = getAlbumNode();
             if (albumNode.hasProperty("description")) {
                 description = albumNode.getProperty("description").getString();
-            } /*else {
-                logger.info("description of album " + name + " not found");
-            } */
+            }
 
         } catch (Exception e) {
-            // FIXME: ignore for now
             e.printStackTrace();
         } finally {
             //repositoryManager.releaseSession();
@@ -159,14 +176,11 @@
     @Property
     public void setDescription(String description) {
         try {
-            Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
-            Node albumNode = root.getNode(name);
+            Node albumNode = getAlbumNode();
             albumNode.setProperty("description", description);
-            session.save();
         } catch (RepositoryException e) {
             e.printStackTrace();
-        }  finally {
+        } finally {
             //repositoryManager.releaseSession();
         }
 
@@ -190,23 +204,15 @@
             init();
         }
         List<String> pictures = new ArrayList<String>();
+
         try {
-            Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
-            Node albumNode = root.getNode(name);
-            NodeIterator nodes = albumNode.getNodes();
-
+            NodeIterator nodes = getAlbumNode().getNodes();
             while (nodes.hasNext()) {
                 Node node = nodes.nextNode();
-                if (node.getPath().equals("/jcr:system")||node.getPath().equals("/userStore"))
-                    continue;
                 pictures.add(node.getProperty("location").getString());
             }
-        } catch (Exception e) {
-            // FIXME: ignore for now
-            e.printStackTrace();
-        } finally {
-            //repositoryManager.releaseSession();
+        } catch (RepositoryException e) {
+
         }
 
         String[] pictureArray = new String[pictures.size()];
@@ -214,17 +220,44 @@
         return pictureArray;
     }
 
+    private Node getAlbumNode() {       // Adhered to new structure
+
+        Node albumNode = null;
+
+        try {
+            Session session = repositoryManager.getSession();
+            Node root = session.getRootNode().getNode("albums");
+
+            if (this.type.equals("local")) {                                             // returns a local album node or if not exists create a new album node
+                if (root.getNode("local").hasNode(name)) {
+                    albumNode = root.getNode("local").getNode(name);
+                } else {
+                    albumNode = root.getNode("local").addNode(name);
+                }
+
+            } else if (this.type.equals("remote")) {                                    // returns a remote node
+                if (root.getNode("remote").hasNode(name)) {
+                    albumNode = root.getNode("remote").getNode(name);
+                } else {
+                    albumNode = root.getNode("remote").addNode(name);
+                }
+
+            }
+            session.save();
+        } catch (Exception e) {
+
+        }
+        return albumNode;
+    }
+
     public void removeNodes() {
         try {
             Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
+            Node root = session.getRootNode().getNode("albums").getNode("local");
             NodeIterator nodes = root.getNodes();
             while (nodes.hasNext()) {
                 Node node = nodes.nextNode();
-                if (node.getPath().equals("/jcr:system"))
-                    continue;
-                else
-                    node.remove();
+                node.remove();
             }
             session.save();
         } catch (Exception e) {
@@ -236,20 +269,27 @@
 
     }
 
-    public void addPicture(Image picture) {
+    public void addPicture(Image picture) {    // Adhered to new structure
+
         try {
+
             Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
-            Node albumNode = root.getNode(name);
-            Node picNode = albumNode.addNode(picture.getName());
-            picture.getImageAsStream();
+            String location = "";
+            if (this.type.equals("local")) {
+                location = picture.getName();
+            } else if (this.type.equals("remote")) {
+                location = picture.getLocation();
+            }
+            Node picNode = getAlbumNode().addNode(picture.getName());
             picNode.setProperty("imageContent", picture.getImageAsStream());
             picNode.setProperty("name", picture.getName());
-            picNode.setProperty("location", picture.getName());
+            picNode.setProperty("location", location);
             session.save();
+
+
         } catch (RepositoryException e) {
             e.printStackTrace();
-        }  finally {
+        } finally {
             //repositoryManager.releaseSession();
         }
     }
@@ -257,14 +297,14 @@
     public void deletePicture(Image picture) {
         try {
             Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
-            Node albumNode = root.getNode(name);
-            Node picNode = albumNode.addNode(picture.getName());
+
+            Node albumNode = getAlbumNode();
+            Node picNode = albumNode.getNode(picture.getName());
             picNode.remove();
             session.save();
         } catch (RepositoryException e) {
             e.printStackTrace();
-        }  finally {
+        } finally {
             //repositoryManager.releaseSession();
         }
     }
@@ -275,7 +315,7 @@
         ownerList.add(owner);
         try {
             Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
+            Node root = session.getRootNode().getNode("albums").getNode("local");
             Node albumNode = root.getNode(name);
             if (albumNode.hasProperty("owners")) {
                 for (Value ownerValue : albumNode.getProperty("owners").getValues()) {
@@ -304,7 +344,7 @@
         }
         try {
             Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
+            Node root = session.getRootNode().getNode("albums").getNode("local");
             if (root.hasNode(name)) {
                 Node albumNode = root.getNode(name);
                 if (albumNode.hasProperty("owners")) {
@@ -327,26 +367,50 @@
         return new String[]{};
     }
 
+    public String[] getOwners(String skip) {      // Adhered to new structure
+
+        try {
+            Session session = repositoryManager.getSession();
+            Node root = session.getRootNode();
+            Node albumNode = getAlbumNode();
+            if (albumNode.hasProperty("owners")) {
+                Value[] values = albumNode.getProperty("owners").getValues();
+                String[] owners = new String[values.length];
+                for (int i = 0; i < values.length; i++) {
+                    owners[i] = values[i].getString();
+                }
+                return owners;
+            }
+
+        } catch (Exception e) {
+            // FIXME: ignore for now
+            e.printStackTrace();
+        } finally {
+            //repositoryManager.releaseSession();
+        }
+        return new String[]{};
+    }
+
     /**
      * This method deletes the picture node.
-     * @param  pictureName
-     * 
+     *
+     * @param pictureName
      */
     public void deletePicture(String pictureName) {
         try {
             Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
-            Node albumNode = root.getNode(name);
-            if(albumNode.hasNode(pictureName)){
+
+            Node albumNode = getAlbumNode();
+            if (albumNode.hasNode(pictureName)) {
                 Node picNode = albumNode.getNode(pictureName);
                 picNode.remove();
                 session.save();
-            }else{
+            } else {
                 logger.info("image " + pictureName + " not found");
-            }    	            
+            }
         } catch (RepositoryException e) {
             e.printStackTrace();
-        }  finally {
+        } finally {
             //repositoryManager.releaseSession();
         }
     }
@@ -354,7 +418,7 @@
     /**
      * This method create new album node in case it does not exists in
      * repository or return older album node otherwise.
-     * 
+     *
      * @param
      * @return
      * @throws RepositoryException
Index: photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumAggregator.java
===================================================================
--- photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumAggregator.java	(revision 0)
+++ photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumAggregator.java	(revision 0)
@@ -0,0 +1,159 @@
+package org.apache.photark.jcr.services;
+
+import java.util.*;
+import java.util.logging.Logger;
+
+import org.apache.photark.jcr.JCRRepositoryManager;
+import org.apache.photark.Image;
+import org.apache.photark.services.album.Album;
+import org.apache.photark.services.album.AlbumAgregator;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+public class JCRAlbumAggregator extends AlbumAgregator {
+
+    private JCRRepositoryManager repositoryManager;
+    private Map<String, Album> localAlbums = new HashMap<String, Album>();
+    private Map<String, Album> remoteAlbums = new HashMap<String, Album>();
+    private boolean isUpdated = false;
+    private List<Album> localAlbumList = new ArrayList<Album>();
+    private List<Album> remoteAlbumList = new ArrayList<Album>();
+    private static final Logger logger = Logger.getLogger(JCRAlbumAggregator.class.getName());
+
+
+    public JCRAlbumAggregator(JCRRepositoryManager repositoryManager) {
+
+        this.repositoryManager = repositoryManager;
+        initJCRAlbumAggregator();
+    }
+
+    private void initJCRAlbumAggregator() {  // should init each time gallery loads
+        loadLocalAlbums();
+        loadRemoteAlbums();
+    }
+
+    public void put(Album album, String type) {
+
+    String albumName = album.getName();
+
+       if((type != null) && (type.equals("local"))) {
+          if(!localAlbums.containsKey(albumName)) {
+            localAlbums.put(albumName,album);
+            localAlbumList.add(album);
+          }
+
+       } else if ((type != null) && ((type.equals("remote")))) {
+           if(!remoteAlbums.containsKey(albumName)) {
+            remoteAlbums.put(albumName,album);
+            remoteAlbumList.add(album);
+          }
+       }
+
+    }
+
+    public void remove(Album album,String type) {
+
+          String albumName = album.getName();
+
+       if((type != null) && (type.equals("local"))) {
+          if(localAlbums.containsKey(albumName)) {
+            localAlbums.remove(album);
+            localAlbumList.remove(album);
+          }
+
+       } else if ((type != null) && (type.equals("remote"))) {
+           if(remoteAlbums.containsKey(albumName)) {
+            remoteAlbums.remove(album);
+            remoteAlbumList.remove(album);
+          }
+       }
+
+
+    }
+
+    public void refreshAlbums() {
+       initJCRAlbumAggregator();
+    }
+
+    public Map<String, Album> getAllLocalAlbums() {
+
+        return localAlbums;
+    }
+
+    public Map<String, Album> getAllRemoteAlbums() {
+
+        return remoteAlbums;
+    }
+
+    public List<Album> getLocalAlbumsAsList() {
+
+        return localAlbumList;
+    }
+
+    public List<Album> getRemoteAlbumsAsList() {
+
+        return remoteAlbumList;
+    }
+
+    public List<Album> getAllAlbumList() {
+        List<Album> list = new ArrayList<Album>();
+        list.addAll(localAlbumList);
+        list.addAll(remoteAlbumList);
+        return list;
+    }
+
+    private void loadLocalAlbums() {
+
+        try {
+
+            Session session = repositoryManager.getSession();
+            Node rootNode = session.getRootNode().getNode("albums");
+
+            NodeIterator nit = rootNode.getNode("local").getNodes();
+
+            while (nit.hasNext()) {
+
+                Node albumNode = nit.nextNode();
+                String albumName = albumNode.getName();
+
+                Album album = new JCRAlbumImpl(repositoryManager, albumName, "local");
+                if (!localAlbums.containsKey(albumName)) {
+                    localAlbums.put(albumName, album);
+                    localAlbumList.add(album);
+                }
+            }
+
+        } catch (RepositoryException e) {
+
+        }
+    }
+
+    private void loadRemoteAlbums() {
+        try {
+
+            Session session = repositoryManager.getSession();
+            Node rootNode = session.getRootNode().getNode("albums");
+
+            NodeIterator nit = rootNode.getNode("remote").getNodes();
+
+            while (nit.hasNext()) {
+                    Node albumNode = nit.nextNode();
+                    String albumName = albumNode.getName();
+                    Album album = new JCRAlbumImpl(repositoryManager, albumName, "remote");
+                    if (!remoteAlbums.containsKey(albumName)) {
+                        remoteAlbums.put(albumName, album);
+                        remoteAlbumList.add(album);
+                    }
+
+            }
+
+        } catch (RepositoryException e) {
+
+        }
+
+    }
+
+}
Index: photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java
===================================================================
--- photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java	(revision 1059763)
+++ photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java	(working copy)
@@ -321,4 +321,4 @@
 		}
 		return false;
 	}
-}
+}
\ No newline at end of file
Index: photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRRemoteGalleryImpl.java
===================================================================
--- photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRRemoteGalleryImpl.java	(revision 0)
+++ photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRRemoteGalleryImpl.java	(revision 0)
@@ -0,0 +1,352 @@
+package org.apache.photark.jcr.services;
+
+import org.apache.photark.services.gallery.GalleryListener;
+import org.apache.photark.services.gallery.RemoteGallery;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Logger;
+
+import javax.jcr.*;
+
+import org.apache.photark.Image;
+import org.apache.photark.jcr.JCRRepositoryManager;
+import org.apache.photark.security.authorization.services.AccessManager;
+import org.apache.photark.services.album.Album;
+import org.apache.photark.services.gallery.BaseGalleryImpl;
+import org.apache.photark.services.gallery.Gallery;
+import org.oasisopen.sca.annotation.*;
+import org.oasisopen.sca.annotation.Property;
+
+import static org.apache.photark.security.utils.Constants.*;
+
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: subash
+ * Date: Jan 27, 2011
+ * Time: 4:43:03 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@Scope("COMPOSITE")
+public class JCRRemoteGalleryImpl implements RemoteGallery {
+
+    private static final Logger logger = Logger.getLogger(JCRRemoteGalleryImpl.class.getName());
+
+    @Reference(required = false)
+    public GalleryListener listeners;
+
+    private JCRRepositoryManager repositoryManager;
+    private AccessManager accessManager;
+    private JCRAlbumAggregator albumAggregator;
+    int i = 0;
+    public String name = "";
+
+    public JCRRemoteGalleryImpl() {
+
+    }
+
+    @Reference(name = "repositoryManager")
+    protected void setRepositoryManager(JCRRepositoryManager repositoryManager) {
+        this.repositoryManager = repositoryManager;
+        initAlbumAggregator();
+        initBaseJCRStructure();
+    }
+
+    @Property
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @AllowsPassByReference
+    public void imageAdded(String albumName, Image image) {
+
+        if (this.listeners != null) {
+
+//            for (GalleryListener listener : listeners) {
+//                listener.imageAdded(image);
+//            }
+            listeners.imageAdded(albumName, image);
+
+        }
+
+    }
+
+    @AllowsPassByReference
+    public void imageRemoved(String albumName, Image image) {
+
+        if (this.listeners != null) {
+
+//            for (GalleryListener listener : listeners) {
+//                listener.imageRemoved(image);
+//            }
+            listeners.imageRemoved(albumName, image);
+
+        }
+
+    }
+
+    private void initBaseJCRStructure() {
+        try {
+            Session session = repositoryManager.getSession();
+            Node baseRoot = session.getRootNode();
+            Node rootNode;
+
+            if (!baseRoot.hasNode("albums")) {
+                rootNode = baseRoot.addNode("albums");
+            } else {
+                rootNode = baseRoot.getNode("albums");
+            }
+
+            if (!rootNode.hasNode("remote")) {
+                rootNode.addNode("remote");
+            }
+
+            if (!rootNode.hasNode("local")) {
+                rootNode.addNode("local");
+            }
+
+        } catch (RepositoryException e) {
+            e.printStackTrace();
+        } finally {
+
+        }
+
+    }
+
+    @Reference(name = "accessmanager")
+    protected void setAccessService(AccessManager accessManager) {
+        this.accessManager = accessManager;
+    }
+
+    private void initAlbumAggregator() {
+        albumAggregator = new JCRAlbumAggregator(repositoryManager);
+    }
+
+    @Init
+    public void init() {
+        albumAggregator.refreshAlbums();
+    }
+
+    public void addAlbum(String albumName, String albumType) {  // Adhered to new structure
+
+        try {
+
+            Session session = repositoryManager.getSession();
+            Node rootNode = session.getRootNode().getNode("albums");
+
+            //adding albums to local JCR
+
+            if ((albumType != null) && (albumType.equals("remote"))) {
+
+                Node remote = rootNode.getNode("remote");
+
+                if (remote.hasNode(albumName)) {
+                    logger.info("This album is already in gallery");
+                    return;
+
+                }
+
+                remote.addNode(albumName);
+                session.save();
+
+            } else if ((albumType != null) && (albumType.equals("local"))) {
+
+                Node local = rootNode.getNode("local");
+
+                if (local.hasNode(albumName)) {
+                    logger.info("This album is already in gallery");
+                    return;
+                }
+
+                local.addNode(albumName);
+                session.save();
+
+            }
+
+            Album album = JCRAlbumImpl.createAlbum(repositoryManager, albumName, albumType);
+            albumAggregator.put(album, albumType);
+
+        } catch (RepositoryException e) {
+            e.printStackTrace();
+        } finally {
+
+        }
+    }
+
+
+    private Node getAlbumNode(String type, String name) throws RepositoryException { // Adhered to new structure
+
+        Node albumNode = null;
+
+        try {
+            Session session = repositoryManager.getSession();
+            Node root = session.getRootNode().getNode("albums");
+
+            if (type.equals("local")) {
+
+                albumNode = root.getNode("local").getNode(name);
+
+            } else if (type.equals("remote")) {
+
+                albumNode = root.getNode("remote").getNode(name);
+            }
+
+            session.save();
+        }
+        catch (PathNotFoundException e) {
+            throw new PathNotFoundException();
+        }
+        catch (RepositoryException e) {
+            throw new RepositoryException();
+        }
+        return albumNode;
+    }
+
+    public boolean hasAlbum(String albumName, String type) {  // Adhered to new structure
+
+        boolean hasAlbum = true;
+        try {
+            Node rootNode = getAlbumNode(type, albumName);
+
+        } catch (PathNotFoundException e) {
+            hasAlbum = false;
+
+        } catch (RepositoryException e) {
+            hasAlbum = false;
+
+        } finally {
+            //repositoryManager.releaseSession();
+        }
+        return hasAlbum;
+    }
+
+    public void deleteAlbum(String albumName, String type) {  // Adhered to new structure
+        try {
+            Session session = repositoryManager.getSession();
+
+            Node albumNode = getAlbumNode(type, albumName);
+            Album album = JCRAlbumImpl.createAlbum(repositoryManager, albumName);
+            albumAggregator.remove(album, type);
+            albumNode.remove();
+            session.save();
+            logger.info("album " + albumName + " deleted");
+
+        } catch (PathNotFoundException e) {
+            logger.info("album " + albumName + " not found");
+        }
+        catch (RepositoryException e) {
+            e.printStackTrace();
+        } finally {
+            //repositoryManager.releaseSession();
+        }
+    }
+
+    public String[] getAlbumPictures(String albumName, String type) {     // Adhered to new Structure
+        return getAlbumPicturesToUser(albumName, accessManager.getSecurityTokenFromUserId(GUEST), type);
+    }
+
+    public String[] getAlbumPicturesToUser(String albumName, String securityToken, String type) { // Adhered to new Structure
+        String[] permissions = new String[]{ALBUM_VIEW_IMAGES_PERMISSION};
+        if (accessManager.isPermitted(accessManager.getUserIdFromSecurityToken(securityToken), albumName, permissions)) {
+            Album albumLookup = getAlbumFromAggregator(albumName, type);
+            if (albumLookup != null) {
+                return albumLookup.getPictures();
+            } else {
+                // FIXME: return proper not found exception
+                return new String[]{};
+            }
+        } else {
+            return new String[]{};
+        }
+    }
+
+    private Album getAlbumFromAggregator(String albumName, String type) {   // Adhered to new Structure
+        albumAggregator.refreshAlbums();
+        Album album = null;
+        if ((type != null) && (type.equals("local"))) {
+            album = albumAggregator.getAllLocalAlbums().get(albumName);
+        } else if ((type != null) && (type.equals("remote"))) {
+            album = albumAggregator.getAllRemoteAlbums().get(albumName);
+        }
+
+        return album;
+    }
+
+    public String getAlbumCover(String albumName, String type) {       // Adhered to new Structure
+        return getAlbumCoverToUser(albumName, accessManager.getSecurityTokenFromUserId(GUEST), type);
+    }
+
+    public String getAlbumCoverToUser(String albumName, String securityToken, String type) {    // Adhered to new Structure
+        String[] permissions = new String[]{ALBUM_VIEW_IMAGES_PERMISSION};
+        if (accessManager.isPermitted(accessManager.getUserIdFromSecurityToken(securityToken), albumName, permissions)) {
+            Album albumLookup = getAlbumFromAggregator(albumName, type);
+
+            if (albumLookup != null) {
+                String[] pictures = albumLookup.getPictures();
+                // this check is to avoid Exception
+                if (pictures.length > 0) {
+                    return albumLookup.getPictures()[0];
+                } else {
+                    logger.info("No Album Cover Picture found for album:" + albumName);
+                    return null;
+                }
+            } else {
+                // FIXME: return proper not found exception
+                return null;
+            }
+        } else {
+            return null;
+        }
+    }
+
+    public Album[] getAlbums(String type) {            // Adhered to new Structure
+        return getAlbumsToUser(accessManager.getSecurityTokenFromUserId(GUEST), type);
+    }
+
+    public Album[] getAlbumsToUser(String securityToken, String type) {    // Adhered to new Structure
+        albumAggregator.refreshAlbums();
+        List<Album> albumsN = null;
+        List<Album> userAlbums = new ArrayList<Album>();
+
+        if ((type != null) && (type.equals("local"))) {   // all albums of the specified type
+            albumsN = albumAggregator.getLocalAlbumsAsList();
+
+        } else if ((type != null) && ((type.equals("remote")))) {
+            albumsN = albumAggregator.getRemoteAlbumsAsList();
+        }
+
+        for (Album album : albumsN) {
+            String[] permissions = new String[]{ALBUM_VIEW_IMAGES_PERMISSION};
+//               if (accessManager.isPermitted(accessManager.getUserIdFromSecurityToken(securityToken), album.getName(), permissions)) {
+            userAlbums.add(album);
+//               }
+        }
+        Album[] albumArray = new Album[userAlbums.size()];
+        userAlbums.toArray(albumArray);
+        return albumArray;
+    }
+
+    /*this method is used to get the albums, that the user can add to various roles*/
+
+    public Album[] getAlbumsToSetPermission(String securityToken) {     // Adhered to new Structure
+        albumAggregator.refreshAlbums();
+        List<Album> allAlbums = albumAggregator.getAllAlbumList();
+        List<Album> userAlbums = new ArrayList<Album>();
+        for (Album album : allAlbums) {
+            // only the super admin and the album owner is allowed
+//               if (accessManager.isPermitted(accessManager.getUserIdFromSecurityToken(securityToken), album.getName(), null)) {
+            userAlbums.add(album);
+//               }
+        }
+        Album[] albumArray = new Album[userAlbums.size()];
+        userAlbums.toArray(albumArray);
+        return albumArray;
+    }
+
+
+}
Index: photark-jcr/src/main/resources/META-INF/sca-contribution.xml
===================================================================
--- photark-jcr/src/main/resources/META-INF/sca-contribution.xml	(revision 1059763)
+++ photark-jcr/src/main/resources/META-INF/sca-contribution.xml	(working copy)
@@ -20,4 +20,6 @@
 <contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
               xmlns:photark="http://org.apache.photoark">
    <export.java package="org.apache.photark.jcr.services"/>
+   <export.java package="org.apache.photark.services.album"/>
+   <export.java package="org.apache.photark.services.gallery"/>
 </contribution>
Index: photark-jcr/pom.xml
===================================================================
--- photark-jcr/pom.xml	(revision 1059763)
+++ photark-jcr/pom.xml	(working copy)
@@ -39,6 +39,16 @@
 			<artifactId>photark</artifactId>
 			<version>1.0-incubating-SNAPSHOT</version>
 		</dependency>
+         <dependency>
+			<groupId>org.apache.photark</groupId>
+			<artifactId>photark-flickr</artifactId>
+			<version>1.0-incubating-SNAPSHOT</version>
+		</dependency>
+         <dependency>
+			<groupId>org.apache.photark</groupId>
+			<artifactId>photark-picasa</artifactId>
+			<version>1.0-incubating-SNAPSHOT</version>
+		</dependency>
 		
         <!-- Tuscany Dependencies -->
 		<dependency>
Index: photark-picasa/src/main/java/org/apache/photark/album/picasa/PicasaPhotoStream.java
===================================================================
--- photark-picasa/src/main/java/org/apache/photark/album/picasa/PicasaPhotoStream.java	(revision 1059763)
+++ photark-picasa/src/main/java/org/apache/photark/album/picasa/PicasaPhotoStream.java	(working copy)
@@ -157,7 +157,7 @@
         // http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_java.html
 
         image.setId(photo.getGphotoId());
-        image.setName(photo.getTitle().getPlainText());
+        image.setName(photo.getGphotoId());
         image.setTitle(photo.getTitle().getPlainText());
         image.setLocation(photo.getMediaContents().get(0).getUrl());
 
Index: photark-picasa/pom.xml
===================================================================
--- photark-picasa/pom.xml	(revision 1059763)
+++ photark-picasa/pom.xml	(working copy)
@@ -110,6 +110,7 @@
 			<version>4.8.1</version>
 			<scope>test</scope>
 		</dependency>
+
 	</dependencies>
 
 	<build>
Index: photark/src/main/java/org/apache/photark/Image.java
===================================================================
--- photark/src/main/java/org/apache/photark/Image.java	(revision 1059763)
+++ photark/src/main/java/org/apache/photark/Image.java	(working copy)
@@ -38,6 +38,7 @@
     private String name;
     private String title;
     private String imageName;
+    private String imageType = "local";
     private Date datePosted;
     private transient InputStream imageStream;
     private String url;
@@ -82,6 +83,7 @@
      */
     public void setName(String name) {
         this.name = name;
+        this.imageName = name;
     }
 
     
@@ -150,8 +152,23 @@
         this.url = location;
     }
 
+    /**
+     * Set the Image type, whether remote or local
+     */
+    public void setType(String imageType){
+        this.imageType = imageType;
+    }
 
     /**
+     *   Returns Image type as a String
+     * @return  Image Type
+     */
+    public String getType(){
+    return imageType;
+    }
+
+
+    /**
      * Return image content as stream
      * @return image stream
      */
@@ -164,8 +181,8 @@
      * @return list of image metadata attributes
      */
     public List<ImageMetadata> getImageMetadata() {
-        if(imageAttributes == null) {
-            imageAttributes = ImageMetadataScanner.scanImageMetadata(imageName, imageStream);
+        if((imageAttributes == null) && (imageType.equals("local"))) {
+       imageAttributes = ImageMetadataScanner.scanImageMetadata(imageName, imageStream);
         }
         return imageAttributes;
     }
Index: photark/src/main/java/org/apache/photark/services/gallery/Gallery.java
===================================================================
--- photark/src/main/java/org/apache/photark/services/gallery/Gallery.java	(revision 1059763)
+++ photark/src/main/java/org/apache/photark/services/gallery/Gallery.java	(working copy)
@@ -30,6 +30,8 @@
     
     void addAlbum(String albumName);
 
+//    void addAlbum(String albumName, String albumType);
+
     boolean hasAlbum(String albumName);
     
     void deleteAlbum(String albumName);
Index: photark/src/main/java/org/apache/photark/services/gallery/RemoteAlbumSubscription.java
===================================================================
--- photark/src/main/java/org/apache/photark/services/gallery/RemoteAlbumSubscription.java	(revision 0)
+++ photark/src/main/java/org/apache/photark/services/gallery/RemoteAlbumSubscription.java	(revision 0)
@@ -0,0 +1,28 @@
+package org.apache.photark.services.gallery;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: subash
+ * Date: Jan 27, 2011
+ * Time: 9:27:59 AM
+ * To change this template use File | Settings | File Templates.
+ */
+import org.apache.photark.Image;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.oasisopen.sca.annotation.Remotable;
+
+import java.util.Set;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: siddhi
+ * Date: Oct 6, 2010
+ * Time: 3:26:24 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@Remotable
+public interface RemoteAlbumSubscription {
+
+    Entry<String, Image>[] addRemoteAlbum(String url,String alb,String albDesc,String type);
+
+}
\ No newline at end of file
Index: photark/src/main/java/org/apache/photark/services/gallery/RemoteGallery.java
===================================================================
--- photark/src/main/java/org/apache/photark/services/gallery/RemoteGallery.java	(revision 0)
+++ photark/src/main/java/org/apache/photark/services/gallery/RemoteGallery.java	(revision 0)
@@ -0,0 +1,41 @@
+package org.apache.photark.services.gallery;
+
+import org.apache.photark.Image;
+import org.apache.photark.services.album.Album;
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: subash
+ * Date: Jan 27, 2011
+ * Time: 4:43:26 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@Remotable
+public interface RemoteGallery {
+
+    void addAlbum(String albumName, String albumType);
+
+    boolean hasAlbum(String albumName, String type);
+
+    void deleteAlbum(String albumName, String type);
+
+    String[] getAlbumPictures(String albumName, String type);
+
+    String[] getAlbumPicturesToUser(String albumName, String securityToken, String type);
+
+    String getAlbumCover(String albumName, String type);
+
+    String getAlbumCoverToUser(String albumName, String securityToken, String type);
+
+    Album[] getAlbums(String type);
+
+    Album[] getAlbumsToUser(String securityToken, String type);
+
+    Album[] getAlbumsToSetPermission(String securityToken);
+
+    void imageAdded(String albumName, Image image);
+
+    void imageRemoved(String albumName, Image image);
+
+}
\ No newline at end of file
Index: photark/src/main/java/org/apache/photark/services/album/AlbumAgregator.java
===================================================================
--- photark/src/main/java/org/apache/photark/services/album/AlbumAgregator.java	(revision 1059763)
+++ photark/src/main/java/org/apache/photark/services/album/AlbumAgregator.java	(working copy)
@@ -27,7 +27,7 @@
 import org.oasisopen.sca.annotation.Reference;
 
 public class AlbumAgregator implements Album {
-    private static String NAME = "Aggregated Album";
+    private static String NAME = "Album Aggregator";
 
     private List<String> pictures = new ArrayList<String>();
 
Index: photark-ui-admin/src/main/webapp/admin/upload.html
===================================================================
--- photark-ui-admin/src/main/webapp/admin/upload.html	(revision 1059763)
+++ photark-ui-admin/src/main/webapp/admin/upload.html	(working copy)
@@ -73,9 +73,24 @@
                             </div>
                         </td>
                         <td>
+                         <div id="remoteAlb_type"> Select Remote Album
+                              <select  id="selectRemoteAlbum" name="selectRemoteAlbum" >
+                                <option value="Subscribe-Picasa">Picasa</option>
+                                <option value="Subscribe-Flicker">Flicker</option>
+                              </select>
+                            </div>
+                            <div id="remoteAlb_url">Album Url <input type='text' name="remote_alburl" id='remote_alburl'  size='25' value=''>
+                            </div>
+                            <div id="remoteAlb_uname">Username<input type='text' name="remote_albuname" id='remote_albuname' size='25' value=''>
+                            </div>
+                            <div id="remoteAlb_passwd">Password <input type='text' name="remote_albpasswd" id='remote_albpasswd' size='25' value=''>
+                        </div>
                             <label for="albumDescriptionDiv">Album Description</label>
 
                             <div id="albumDescriptionDiv">
+                            </div> <br>
+                             <div id="import_submit" class="uploadBtn btn" onClick="doImportRemoteAlbums();">
+                             Subscribe  
                             </div>
                         </td>
                     </tr>
Index: photark-ui-admin/src/main/webapp/admin/js/upload.js
===================================================================
--- photark-ui-admin/src/main/webapp/admin/js/upload.js	(revision 1059763)
+++ photark-ui-admin/src/main/webapp/admin/js/upload.js	(working copy)
@@ -47,7 +47,7 @@
     });
 };
 
-dojo.addOnLoad( function(){
+dojo.addOnLoad( function() {
 	var fileUploaderConfig = {
 		isDebug:false,
 		hoverClass:"uploadHover",
@@ -75,6 +75,32 @@
 		},fileUploaderConfig), "btnUploader");
 
 
+
+        doImportRemoteAlbums = function() {
+
+        var selectAlbums = dojo.byId("selectRemoteAlbum");
+        var selectedAlb =  selectAlbums.value;
+        var remoteAlbumName = dojo.byId("newAlbumName").value;
+        var albumDescription = dojo.byId("albumDescription").value;
+    	var alburl= dojo.byId("remote_alburl").value;
+	    var albuname= dojo.byId("remote_albuname").value;
+	    var albpasswd= dojo.byId("remote_albpasswd").value;
+
+       if((alburl == "") || (remoteAlbumName == "") ) {
+        alert("Album name and album url fileds are required to proceed !!. Please fill the required fields.");
+       } else if(selectedAlb != null) {
+            var albumSubService =  new dojo.rpc.JsonService(photark.constants.RemoteAlbumSubscription);
+            albumSubService.addRemoteAlbum(alburl,remoteAlbumName,albumDescription,selectedAlb).addCallback(gallery_getRemoteAlbumsSubscriptionResponse);
+       }
+       }
+
+       gallery_getRemoteAlbumsSubscriptionResponse = function(pimages, exception) {
+        if(exception) {
+        logout();
+        }
+            alert("Remote Album Successfully Created..You have Added "+pimages.length+" Images");
+       }
+
 		doUpload = function(){
 			console.log("doUpload");
 			displayProgress();
@@ -98,7 +124,7 @@
 					dojo.byId("progressBar").style.display="none";
 				} else {
 					//add new album to list of albums
-					selectAlbum.options[selectAlbum.options.length] =  new Option(albumName, albumName, false, false);
+                    selectAlbum.options[selectAlbum.options.length] =  new Option(albumName, albumName, false, false);
 					//upload the files
 					setProgressbar(0,1);
 					uploader.upload({albumName:albumName, albumDescription:albumDescription, securityToken:securityToken});
Index: photark-ui-admin/src/main/webapp/admin/js/admin.js
===================================================================
--- photark-ui-admin/src/main/webapp/admin/js/admin.js	(revision 1059763)
+++ photark-ui-admin/src/main/webapp/admin/js/admin.js	(working copy)
@@ -56,6 +56,8 @@
         for (var pos = 0; pos < albums.length; pos++) {
             selectAlbum.options[selectAlbum.options.length] = new Option(albums[pos].name, albums[pos].name, false, false);
         }
+        selectAlbum.options[selectAlbum.options.length] = new Option("New-Remote-Album", "New-Remote-Album", false, false);
+
         dojo.byId("selectAlbum").value = albumName;
         if (currentView == "AlbumOnload" || currentView == "Album") {
             manageAlbumFields();
@@ -138,8 +140,40 @@
         dojo.byId("btnAlbumDesc").style.display = "none";
         dojo.byId("deleteAlbum").style.display = "none";
         dojo.byId("albumDescriptionDiv").innerHTML = "<textarea cols='20' rows='5' class='textarea' name='albumDescription' id='albumDescription'></textarea>";
+
+        dojo.byId("remoteAlb_type").style.display = "none";
+        dojo.byId("remoteAlb_passwd").style.display = "none";
+        dojo.byId("remoteAlb_uname").style.display = "none";
+        dojo.byId("remoteAlb_url").style.display = "none";
+        dojo.byId("import_submit").style.display = "none";
+
+    } else if(albumName =="New-Remote-Album") {
+
+         document.getElementById('albumCoverDiv').innerHTML = "<table id='albumCover' style='width:200px;' border='0' cellspacing='0' cellpadding='1'></table>";
+
+         dojo.byId("newAlbumName").style.display = "";
+         dojo.byId("remoteAlb_passwd").style.display = "";
+         dojo.byId("remoteAlb_uname").style.display = "";
+         dojo.byId("remoteAlb_url").style.display = "";
+         dojo.byId("import_submit").style.display = "";
+         dojo.byId("remoteAlb_type").style.display = "";
+
+         dojo.byId("deleteAlbum").style.display = "none";
+         dojo.byId("albumDescriptionDiv").innerHTML = "<textarea cols='20' rows='5' class='textarea' name='albumDescription' id='albumDescription'></textarea>";
+         dojo.byId("btnUploader").style.display = "none";
+         dojo.byId("btnUpload").style.display = "none";
+         dojo.byId("btnAlbumDesc").style.display = "none";
+         dojo.byId("newAlbumLabel").style.display = "";
+         dojo.byId("filesDiv").style.display = "none";
+
     } else {
 
+         dojo.byId("remoteAlb_type").style.display = "none";
+         dojo.byId("remoteAlb_passwd").style.display = "none";
+         dojo.byId("remoteAlb_uname").style.display = "none";
+         dojo.byId("remoteAlb_url").style.display = "none";
+         dojo.byId("import_submit").style.display = "none";
+
         dojo.byId("newAlbumName").style.display = "none";
         dojo.byId("newAlbumLabel").style.display = "none";
         if (userId == "SuperAdmin" || ( (albums[albumIndex].owners + "").indexOf(userId) != -1) || permissions.indexOf("|" + albumName + ".editAlbumDescription|") != -1) {
