just before adding authorization service.
[photos] / src / main / java / org / wamblee / photos / model / filesystem / FileSystemPhoto.java
diff --git a/src/main/java/org/wamblee/photos/model/filesystem/FileSystemPhoto.java b/src/main/java/org/wamblee/photos/model/filesystem/FileSystemPhoto.java
new file mode 100644 (file)
index 0000000..ec1452b
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2005 the original author or authors.
+ * 
+ * Licensed 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.
+ */ 
+package org.wamblee.photos.model.filesystem;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.wamblee.photos.model.Photo;
+import org.wamblee.photos.model.PhotoEntry;
+
+/**
+ * Represents a photo stored on the file system.
+ */
+public class FileSystemPhoto implements Photo {
+
+       private File _thumbnail;
+       private File _photo;
+       private String _path; 
+
+       public FileSystemPhoto(File aThumbnail, File aPhoto, String aPath) {
+               _thumbnail = aThumbnail;
+               _photo = aPhoto;
+               _path = aPath;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see org.wamblee.photos.database.PhotoEntry#getPath()
+        */
+       public String getPath() {
+               return _path;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see org.wamblee.photos.database.Photo#getThumbNail()
+        */
+       public InputStream getThumbNail() throws IOException {
+               return openFile(_thumbnail);
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see org.wamblee.photos.database.Photo#getFile()
+        */
+       public InputStream getPhoto() throws IOException {
+               return openFile(_photo);
+       }
+
+       private InputStream openFile(File aFile) throws FileNotFoundException {
+               return new FileInputStream(aFile);
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see org.wamblee.photos.database.PhotoEntry#getId()
+        */
+       public String getId() {
+               return getId(_path);
+       }
+    
+    public static String getId(String aPath) {
+        int index = aPath.lastIndexOf("/");
+        if (index < 0) {
+            return aPath;
+        }
+        return aPath.substring(index + 1);
+    }
+
+       public String toString() {
+               return print("");
+       }
+
+       String print(String aIndent) {
+               return aIndent + "IMG: " + _photo.getName();
+       }
+    
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if ( !(obj instanceof Photo) ) { 
+            return false; 
+        }
+        return getPath().equals( ((Photo)obj).getPath()); 
+    }
+    
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return getPath().hashCode();
+    }
+    
+    /* (non-Javadoc)
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    public int compareTo(PhotoEntry aEntry) {
+        return getId().compareTo(((PhotoEntry)aEntry).getId()); 
+    }
+}