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:49:26 UTC
svn commit: r814420 - in /incubator/photark/trunk:
photark-embedded/src/main/resources/META-INF/
photark-webapp/src/main/webapp/META-INF/
photark/src/main/java/org/apache/photark/services/album/
photark/src/main/java/org/apache/photark/services/album/f...
Author: lresende
Date: Sun Sep 13 22:49:26 2009
New Revision: 814420
URL: http://svn.apache.org/viewvc?rev=814420&view=rev
Log:
Initial prototype of a gallery facade
Added:
incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/
incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java
- copied, changed from r814417, incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java
incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/
incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/GalleryImpl.java
- copied, changed from r814417, incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/filesystem/AlbumImpl.java
incubator/photark/trunk/photark/src/test/
incubator/photark/trunk/photark/src/test/java/
incubator/photark/trunk/photark/src/test/java/org/
incubator/photark/trunk/photark/src/test/java/org/apache/
incubator/photark/trunk/photark/src/test/java/org/apache/photark/
incubator/photark/trunk/photark/src/test/java/org/apache/photark/services/
incubator/photark/trunk/photark/src/test/java/org/apache/photark/services/gallery/
incubator/photark/trunk/photark/src/test/java/org/apache/photark/services/gallery/filesystem/
incubator/photark/trunk/photark/src/test/java/org/apache/photark/services/gallery/filesystem/GalleryTestCase.java
- copied, changed from r814417, incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java
Modified:
incubator/photark/trunk/photark-embedded/src/main/resources/META-INF/sca-contribution.xml
incubator/photark/trunk/photark-webapp/src/main/webapp/META-INF/sca-contribution.xml
incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java
incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/AlbumAgregator.java
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/album/jcr/AlbumImpl.java
incubator/photark/trunk/photark/src/main/resources/META-INF/sca-contribution.xml
Modified: incubator/photark/trunk/photark-embedded/src/main/resources/META-INF/sca-contribution.xml
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-embedded/src/main/resources/META-INF/sca-contribution.xml?rev=814420&r1=814419&r2=814420&view=diff
==============================================================================
--- incubator/photark/trunk/photark-embedded/src/main/resources/META-INF/sca-contribution.xml (original)
+++ incubator/photark/trunk/photark-embedded/src/main/resources/META-INF/sca-contribution.xml Sun Sep 13 22:49:26 2009
@@ -22,4 +22,6 @@
<import.java package="org.apache.photark.services.album"/>
<import.java package="org.apache.photark.services.album.filesystem"/>
<import.java package="org.apache.photark.services.album.jcr"/>
+ <import.java package="org.apache.photark.services.gallery"/>
+ <import.java package="org.apache.photark.services.gallery.filesystem"/>
</contribution>
\ No newline at end of file
Modified: incubator/photark/trunk/photark-webapp/src/main/webapp/META-INF/sca-contribution.xml
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-webapp/src/main/webapp/META-INF/sca-contribution.xml?rev=814420&r1=814419&r2=814420&view=diff
==============================================================================
--- incubator/photark/trunk/photark-webapp/src/main/webapp/META-INF/sca-contribution.xml (original)
+++ incubator/photark/trunk/photark-webapp/src/main/webapp/META-INF/sca-contribution.xml Sun Sep 13 22:49:26 2009
@@ -22,5 +22,8 @@
<import.java package="org.apache.photark.services.album"/>
<import.java package="org.apache.photark.services.album.filesystem"/>
<import.java package="org.apache.photark.services.album.jcr"/>
+ <import.java package="org.apache.photark.services.gallery"/>
+ <import.java package="org.apache.photark.services.gallery.filesystem"/>
+
<deployable composite="photark:photo-gallery"/>
</contribution>
Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java?rev=814420&r1=814419&r2=814420&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java Sun Sep 13 22:49:26 2009
@@ -28,6 +28,9 @@
void setName(String name);
+ String getLocation();
+
+ void setLocation(String location);
+
String[] getPictures();
-
}
Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/AlbumAgregator.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/AlbumAgregator.java?rev=814420&r1=814419&r2=814420&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/AlbumAgregator.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/AlbumAgregator.java Sun Sep 13 22:49:26 2009
@@ -81,6 +81,14 @@
throw new UnsupportedOperationException();
}
+ public String getLocation() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setLocation(String location) {
+ throw new UnsupportedOperationException();
+ }
+
public String[] getPictures() {
String[] pictureArray = new String[pictures.size()];
pictures.toArray(pictureArray);
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=814420&r1=814419&r2=814420&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:49:26 2009
@@ -84,13 +84,17 @@
return pictureArray;
}
- private String getLocation() {
+ public String getLocation() {
if (location == null) {
location = gallery + "/" + name + "/";
}
return location;
}
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
/**
* Inner fileFilter class
*/
Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java?rev=814420&r1=814419&r2=814420&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java Sun Sep 13 22:49:26 2009
@@ -99,14 +99,17 @@
this.location = null;
}
- protected String getLocation() {
+ public String getLocation() {
if (location == null) {
location = gallery + "/" + name + "/";
}
return location;
}
-
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
public String[] getPictures() {
List<String> pictures = new ArrayList<String>();
Copied: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java (from r814417, incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java)
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java?p2=incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java&p1=incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java&r1=814417&r2=814420&rev=814420&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/Gallery.java Sun Sep 13 22:49:26 2009
@@ -6,28 +6,30 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
+package org.apache.photark.services.gallery;
-package org.apache.photark.services.album;
-
+import org.apache.photark.services.album.Album;
import org.osoa.sca.annotations.Remotable;
@Remotable
-public interface Album {
+public interface Gallery {
String getName();
void setName(String name);
- String[] getPictures();
-
+ void addAlbum(Album album);
+
+ Album[] getAlbums();
+
}
Copied: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/GalleryImpl.java (from r814417, 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/gallery/filesystem/GalleryImpl.java?p2=incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/filesystem/GalleryImpl.java&p1=incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/filesystem/AlbumImpl.java&r1=814417&r2=814420&rev=814420&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/gallery/filesystem/GalleryImpl.java Sun Sep 13 22:49:26 2009
@@ -6,52 +6,66 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
-package org.apache.photark.services.album.filesystem;
+package org.apache.photark.services.gallery.filesystem;
import java.io.File;
-import java.io.FilenameFilter;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.photark.services.album.Album;
+import org.apache.photark.services.gallery.Gallery;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Property;
-
-public class AlbumImpl implements Album {
- private String gallery;
+public class GalleryImpl implements Gallery {
private String name;
private String location;
- private List<String> pictures = new ArrayList<String>();
+ private boolean initialized;
+ private List<Album> albums = new ArrayList<Album>();
+
+ public GalleryImpl() {
+
+ }
+
+ public GalleryImpl(String name) {
+ this.name = name;
+ }
+
@Init
public void init() {
try {
- URL albumURL = this.getClass().getClassLoader().getResource(getLocation());
- if(albumURL == null) {
+ URL galleryURL = this.getClass().getClassLoader().getResource(getLocation());
+ if(galleryURL == null) {
// Accomodate for J2EE classpath that starts in WEB-INF\classes
- albumURL = this.getClass().getClassLoader().getResource("../../" + getLocation());
+ galleryURL = this.getClass().getClassLoader().getResource("../../" + getLocation());
}
- if(albumURL != null) {
- File album = new File(albumURL.toURI());
+ if(galleryURL != null) {
+ File album = new File(galleryURL.toURI());
if (album.isDirectory() && album.exists()) {
- String[] listPictures = album.list(new ImageFilter(".jpg"));
- for(String image : listPictures) {
- image = getLocation() + image;
- pictures.add(image);
+ File[] albums = album.listFiles();
+ for(File albumFile : albums) {
+ if(! albumFile.getName().startsWith(".")) {
+ if(albumFile.isDirectory() && albumFile.exists()) {
+ Album newAlbum = new org.apache.photark.services.album.filesystem.AlbumImpl();
+ newAlbum.setName(albumFile.getName());
+ newAlbum.setLocation(albumFile.getPath());
+ this.albums.add(newAlbum);
+ }
+ }
}
}
}
@@ -59,12 +73,8 @@
// FIXME: ignore for now
e.printStackTrace();
}
- }
-
- @Property
- public void setGallery(String gallery) {
- this.gallery = gallery;
- this.location = null;
+
+ initialized = true;
}
public String getName() {
@@ -77,31 +87,24 @@
this.location = null;
}
-
- public String[] getPictures() {
- String[] pictureArray = new String[pictures.size()];
- pictures.toArray(pictureArray);
- return pictureArray;
+ public void addAlbum(Album album) {
+
+ }
+
+ public Album[] getAlbums() {
+ if(! initialized) {
+ init();
+ }
+
+ Album[] albumArray = new Album[albums.size()];
+ albums.toArray(albumArray);
+ return albumArray;
}
private String getLocation() {
- if (location == null) {
- location = gallery + "/" + name + "/";
+ if(location == null) {
+ location = name;
}
return location;
}
-
- /**
- * Inner fileFilter class
- */
- private class ImageFilter implements FilenameFilter {
- String afn;
- ImageFilter(String afn) { this.afn = afn; }
- public boolean accept(File dir, String name) {
- // Strip path information:
- String f = new File(name).getName();
- return f.indexOf(afn) != -1;
- }
- }
-
}
Modified: incubator/photark/trunk/photark/src/main/resources/META-INF/sca-contribution.xml
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/resources/META-INF/sca-contribution.xml?rev=814420&r1=814419&r2=814420&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/resources/META-INF/sca-contribution.xml (original)
+++ incubator/photark/trunk/photark/src/main/resources/META-INF/sca-contribution.xml Sun Sep 13 22:49:26 2009
@@ -21,4 +21,6 @@
<export.java package="org.apache.photark.services.album"/>
<export.java package="org.apache.photark.services.album.filesystem"/>
<export.java package="org.apache.photark.services.album.jcr"/>
+ <export.java package="org.apache.photark.services.gallery"/>
+ <export.java package="org.apache.photark.services.gallery.filesystem"/>
</contribution>
\ No newline at end of file
Copied: incubator/photark/trunk/photark/src/test/java/org/apache/photark/services/gallery/filesystem/GalleryTestCase.java (from r814417, incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java)
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/test/java/org/apache/photark/services/gallery/filesystem/GalleryTestCase.java?p2=incubator/photark/trunk/photark/src/test/java/org/apache/photark/services/gallery/filesystem/GalleryTestCase.java&p1=incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java&r1=814417&r2=814420&rev=814420&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/album/Album.java (original)
+++ incubator/photark/trunk/photark/src/test/java/org/apache/photark/services/gallery/filesystem/GalleryTestCase.java Sun Sep 13 22:49:26 2009
@@ -17,17 +17,29 @@
* under the License.
*/
-package org.apache.photark.services.album;
+package org.apache.photark.services.gallery.filesystem;
-import org.osoa.sca.annotations.Remotable;
+import junit.framework.Assert;
-@Remotable
-public interface Album {
-
- String getName();
+import org.apache.photark.services.album.Album;
+import org.apache.photark.services.gallery.Gallery;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class GalleryTestCase {
+ private static Gallery gallery;
- void setName(String name);
+ @BeforeClass
+ public static void BeforeClass() {
+ gallery = new GalleryImpl("gallery-home");
+ }
- String[] getPictures();
-
+ @Test
+ public void testDiscoverAlbums() {
+ Album[] albums = gallery.getAlbums();
+
+ Assert.assertEquals(2, albums.length);
+ Assert.assertEquals("album-1", albums[0].getName());
+ Assert.assertEquals("album-2", albums[1].getName());
+ }
}