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 2010/02/14 05:03:02 UTC
svn commit: r909970 - in /incubator/photark/trunk:
photark-jcr/src/main/java/org/apache/photark/services/album/jcr/
photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/
photark-jcr/src/main/java/org/apache/photark/upload/ photark/src/main...
Author: lresende
Date: Sun Feb 14 05:03:02 2010
New Revision: 909970
URL: http://svn.apache.org/viewvc?rev=909970&view=rev
Log:
Formatting...
Modified:
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/GalleryImpl.java
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/JCRSession.java
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/ArchiveFileExtractor.java
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/FileUploader.java
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/PhotoUploadServlet.java
incubator/photark/trunk/photark/src/main/java/org/apache/photark/Picture.java
incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/ImageDisplayer.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/gallery/AbsGalleryImpl.java
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/album/jcr/AlbumImpl.java Sun Feb 14 05:03:02 2010
@@ -40,60 +40,57 @@
import org.oasisopen.sca.annotation.Init;
import org.oasisopen.sca.annotation.Property;
-
public class AlbumImpl implements Album {
private String gallery;
private String name;
private String location;
- private Session session=JCRSession.getSession();
+ private Session session = JCRSession.getSession();
private boolean initialized;
private static Map<String, Album> albums = new HashMap<String, Album>();
-
- public synchronized static Album createAlbum(String name)
- {
- if (!albums.containsKey(name)) {
- albums.put(name, new AlbumImpl(name));
- }
- return albums.get(name);
+
+ public synchronized static Album createAlbum(String name) {
+ if (!albums.containsKey(name)) {
+ albums.put(name, new AlbumImpl(name));
+ }
+ return albums.get(name);
}
- public AlbumImpl(String name){
- this.name = name;
+ public AlbumImpl(String name) {
+ this.name = name;
}
-
+
@Init
public void init() {
System.out.println(">>> Initializing JCR Album");
try {
URL albumURL = this.getClass().getClassLoader().getResource(getLocation());
- if(albumURL == null){
- String loc = "../../" + getLocation();
- albumURL = this.getClass().getClassLoader().getResource(loc);
+ if (albumURL == null) {
+ String loc = "../../" + getLocation();
+ albumURL = this.getClass().getClassLoader().getResource(loc);
}
- if(albumURL != null) {
+ if (albumURL != null) {
try {
- File album = new File(albumURL.toURI());
- if (album.isDirectory() && album.exists()) {
- String[] listPictures = album.list(new ImageFilter(".jpg"));
- if(listPictures !=null && listPictures.length > 0){
- Node albumNode = getAlbumNode(name);
- for(String image : listPictures) {
- if(!albumNode.hasNode(image))
- {
- Node picNode=albumNode.addNode(image);
- String imagePath = albumURL.getPath() + image;
- InputStream imageContent = new FileInputStream(new File(imagePath));
- picNode.setProperty("imageContent", imageContent );
- picNode.setProperty("name", image);
- picNode.setProperty("location", image);
- }
- }
- }
- }
+ File album = new File(albumURL.toURI());
+ if (album.isDirectory() && album.exists()) {
+ String[] listPictures = album.list(new ImageFilter(".jpg"));
+ if (listPictures != null && listPictures.length > 0) {
+ Node albumNode = getAlbumNode(name);
+ for (String image : listPictures) {
+ if (!albumNode.hasNode(image)) {
+ Node picNode = albumNode.addNode(image);
+ String imagePath = albumURL.getPath() + image;
+ InputStream imageContent = new FileInputStream(new File(imagePath));
+ picNode.setProperty("imageContent", imageContent);
+ picNode.setProperty("name", image);
+ picNode.setProperty("location", image);
+ }
+ }
+ }
+ }
- session.save();
- }catch (Exception e){
+ session.save();
+ } catch (Exception e) {
// FIXME: ignore for now
e.printStackTrace();
}
@@ -104,18 +101,17 @@
}
initialized = true;
}
-
@Property
public void setGallery(String gallery) {
this.gallery = gallery;
this.location = null;
}
-
+
public String getName() {
return name;
}
-
+
@Property
public void setName(String name) {
this.name = name;
@@ -129,95 +125,97 @@
return location;
}
-
+
public void setLocation(String location) {
- System.out.println("inside setLocation:location:"+location);
+ System.out.println("inside setLocation:location:" + location);
this.location = location;
}
public synchronized String[] getPictures() {
- if(!initialized){
- init();
- }
- List<String> pictures = new ArrayList<String>();
- try{
- Node root = session.getRootNode();
- Node albumNode = root.getNode(name);
- NodeIterator nodes = albumNode.getNodes();
-
- while(nodes.hasNext()){
- Node node=nodes.nextNode();
- if(node.getPath().equals("/jcr:system")) continue;
- pictures.add(node.getProperty("location").getString());
- }
- }catch (Exception e) {
- // FIXME: ignore for now
- e.printStackTrace();
- }
-
- String[] pictureArray = new String[pictures.size()];
- pictures.toArray(pictureArray);
- return pictureArray;
- }
-
-
- public void removeNodes(){
- try{
- Node root=session.getRootNode();
- NodeIterator nodes = root.getNodes();
- while(nodes.hasNext()){
- Node node=nodes.nextNode();
- if(node.getPath().equals("/jcr:system")) continue;
- else node.remove();
- }
- session.save();
- }catch (Exception e) {
- // FIXME: ignore for now
- e.printStackTrace();
- }
-
- }
-
- public void addPicture(Picture picture){
- try {
- Node root = session.getRootNode();
- Node albumNode = root.getNode(name);
- Node picNode = albumNode.addNode(picture.getName());
- picture.getInputStream();
- picNode.setProperty("imageContent", picture.getInputStream());
- picNode.setProperty("name", picture.getName());
- picNode.setProperty("location", picture.getName());
- session.save();
- } catch (RepositoryException e) {
- e.printStackTrace();
- }
- }
-
- public void deletePicture(Picture picture){
- try {
- Node root = session.getRootNode();
- Node albumNode = root.getNode(name);
- Node picNode = albumNode.addNode(picture.getName());
- picNode.remove();
- session.save();
- } catch (RepositoryException e) {
- e.printStackTrace();
- }
+ if (!initialized) {
+ init();
+ }
+ List<String> pictures = new ArrayList<String>();
+ try {
+ Node root = session.getRootNode();
+ Node albumNode = root.getNode(name);
+ NodeIterator nodes = albumNode.getNodes();
+
+ while (nodes.hasNext()) {
+ Node node = nodes.nextNode();
+ if (node.getPath().equals("/jcr:system"))
+ continue;
+ pictures.add(node.getProperty("location").getString());
+ }
+ } catch (Exception e) {
+ // FIXME: ignore for now
+ e.printStackTrace();
+ }
+
+ String[] pictureArray = new String[pictures.size()];
+ pictures.toArray(pictureArray);
+ return pictureArray;
+ }
+
+ public void removeNodes() {
+ try {
+ Node root = session.getRootNode();
+ NodeIterator nodes = root.getNodes();
+ while (nodes.hasNext()) {
+ Node node = nodes.nextNode();
+ if (node.getPath().equals("/jcr:system"))
+ continue;
+ else
+ node.remove();
+ }
+ session.save();
+ } catch (Exception e) {
+ // FIXME: ignore for now
+ e.printStackTrace();
+ }
+
+ }
+
+ public void addPicture(Picture picture) {
+ try {
+ Node root = session.getRootNode();
+ Node albumNode = root.getNode(name);
+ Node picNode = albumNode.addNode(picture.getName());
+ picture.getInputStream();
+ picNode.setProperty("imageContent", picture.getInputStream());
+ picNode.setProperty("name", picture.getName());
+ picNode.setProperty("location", picture.getName());
+ session.save();
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ }
}
-
-
+
+ public void deletePicture(Picture picture) {
+ try {
+ Node root = session.getRootNode();
+ Node albumNode = root.getNode(name);
+ Node picNode = albumNode.addNode(picture.getName());
+ picNode.remove();
+ session.save();
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ }
+ }
+
/**
- * This method create new album node in case it does not exists in repository or return older album node otherwise.
- *
+ * This method create new album node in case it does not exists in
+ * repository or return older album node otherwise.
+ *
* @param albumName
* @return
* @throws RepositoryException
*/
- private Node getAlbumNode(String name) throws RepositoryException{
- Node root = session.getRootNode();
- if(root.hasNode(name))
- return root.getNode(name);
- else
- return root.addNode(name);
+ private Node getAlbumNode(String name) throws RepositoryException {
+ Node root = session.getRootNode();
+ if (root.hasNode(name))
+ return root.getNode(name);
+ else
+ return root.addNode(name);
}
-}
\ No newline at end of file
+}
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/GalleryImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/GalleryImpl.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/GalleryImpl.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/GalleryImpl.java Sun Feb 14 05:03:02 2010
@@ -33,38 +33,38 @@
import org.apache.photark.services.gallery.Gallery;
import org.oasisopen.sca.annotation.Init;
-public class GalleryImpl extends AbsGalleryImpl implements Gallery{
-
+public class GalleryImpl extends AbsGalleryImpl implements Gallery {
+
public GalleryImpl() {
-
+
}
-
+
public GalleryImpl(String name) {
super(name);
}
-
+
@Init
public void init() {
- System.out.println(">>> Initializing JCR Gallery");
+ System.out.println(">>> Initializing JCR Gallery");
try {
URL galleryURL = this.getClass().getClassLoader().getResource(name);
- if(galleryURL == null) {
+ if (galleryURL == null) {
// Accomodate for J2EE classpath that starts in WEB-INF\classes
galleryURL = this.getClass().getClassLoader().getResource("../../" + name);
}
- if(galleryURL != null) {
+ if (galleryURL != null) {
File album = new File(galleryURL.toURI());
if (album.isDirectory() && album.exists()) {
File[] albums = album.listFiles();
- for(File albumFile : albums) {
- if(! albumFile.getName().startsWith(".")) {
- if(albumFile.isDirectory() && albumFile.exists()) {
+ for (File albumFile : albums) {
+ if (!albumFile.getName().startsWith(".")) {
+ if (albumFile.isDirectory() && albumFile.exists()) {
Album newAlbum = AlbumImpl.createAlbum(albumFile.getName());
newAlbum.setName(albumFile.getName());
((AlbumImpl)newAlbum).setGallery(name);
this.albums.add(newAlbum);
- }
+ }
}
}
}
@@ -74,42 +74,44 @@
// FIXME: ignore for now
e.printStackTrace();
}
-
+
initialized = true;
}
-
-
- private void getAlbumsFromJcrRepository(){
- try {
- Session session = JCRSession.getSession();
- Node rootNode = session.getRootNode();
- NodeIterator albumNodes = rootNode.getNodes();
- while(albumNodes.hasNext()){
- Node albumNode = albumNodes.nextNode();
- if(albumNode.getPath().equals("/jcr:system")) continue;
- String albumName = albumNode.getName();
- Album album = AlbumImpl.createAlbum(albumName);
- if(!albums.contains(album))
- albums.add(album);
- }
- } catch (RepositoryException e) {
- e.printStackTrace();
- }
+
+ private void getAlbumsFromJcrRepository() {
+ try {
+ Session session = JCRSession.getSession();
+ Node rootNode = session.getRootNode();
+ NodeIterator albumNodes = rootNode.getNodes();
+ while (albumNodes.hasNext()) {
+ Node albumNode = albumNodes.nextNode();
+ if (albumNode.getPath().equals("/jcr:system")) {
+ continue;
+ }
+ String albumName = albumNode.getName();
+ Album album = AlbumImpl.createAlbum(albumName);
+ if (!albums.contains(album)) {
+ albums.add(album);
+ }
+ }
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ }
}
-
+
public void addAlbum(String albumName) {
- Session session = JCRSession.getSession();
- try {
- Node rootNode = session.getRootNode();
- if(rootNode.hasNode(albumName)){
- System.out.println("This album is already in gallery");
- return;
- }
- // add album to the root
- rootNode.addNode(albumName);
- session.save();
- } catch (RepositoryException e){
- e.printStackTrace();
- }
- }
-}
\ No newline at end of file
+ Session session = JCRSession.getSession();
+ try {
+ Node rootNode = session.getRootNode();
+ if (rootNode.hasNode(albumName)) {
+ System.out.println("This album is already in gallery");
+ return;
+ }
+ // add album to the root
+ rootNode.addNode(albumName);
+ session.save();
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ }
+ }
+}
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/JCRSession.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/JCRSession.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/JCRSession.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/services/gallery/jcr/JCRSession.java Sun Feb 14 05:03:02 2010
@@ -30,27 +30,26 @@
import org.apache.jackrabbit.core.TransientRepository;
public class JCRSession {
-
- private static Session session;
-
- private static void initSession(){
- try {
- Repository repository = new TransientRepository();
- session = repository.login(new SimpleCredentials("username",
- "password".toCharArray()));
- } catch (LoginException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (RepositoryException e) {
- e.printStackTrace();
- }
- }
-
- public synchronized static Session getSession(){
- if(session == null){
- initSession();
- }
- return session;
- }
-}
\ No newline at end of file
+
+ private static Session session;
+
+ private static void initSession() {
+ try {
+ Repository repository = new TransientRepository();
+ session = repository.login(new SimpleCredentials("username", "password".toCharArray()));
+ } catch (LoginException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public synchronized static Session getSession() {
+ if (session == null) {
+ initSession();
+ }
+ return session;
+ }
+}
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/ArchiveFileExtractor.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/ArchiveFileExtractor.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/ArchiveFileExtractor.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/ArchiveFileExtractor.java Sun Feb 14 05:03:02 2010
@@ -33,75 +33,64 @@
import org.apache.commons.io.IOUtils;
import org.apache.photark.Picture;
+public class ArchiveFileExtractor {
+ private String entryTypes[];
-public class ArchiveFileExtractor
-{
- private String entryTypes[];
-
- public ArchiveFileExtractor(String [] entryTypes){
- this.entryTypes = entryTypes;
- }
-
- public List<Picture> extractArchive(InputStream inStream){
- ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
- List<Picture> pictures = new ArrayList<Picture>();
- try
- {
- ArchiveInputStream archiveInputStream = streamFactory.createArchiveInputStream(inStream);
- ArchiveEntry entry = null;
- while((entry = archiveInputStream.getNextEntry())!= null){
- if(!entry.isDirectory() && isEntryTypeAllowd(entry)){
- byte buf[] = IOUtils.toByteArray(archiveInputStream);
- InputStream inputStream = new ByteArrayInputStream(buf);
- Picture picture = new Picture(entry.getName(), new Date(), inputStream);
- pictures.add(picture);
- }
- }
- }
- catch (ArchiveException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- return pictures;
- }
-
-
- /**
- * Test whether this stream is of archive type or not
- *
- * @param inStream InputStream
- *
- * @return boolean
- */
- public boolean isArchive(InputStream inStream){
- ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
- try {
- streamFactory.createArchiveInputStream(inStream);
- return true;
- } catch (ArchiveException e) {
- e.printStackTrace();
- }
- return false;
- }
-
-
- /**
- * Test weather the extension of given entry is allowed or not
- *
- * @param entry ArchiveEntry
- *
- * @return boolean
- */
- private boolean isEntryTypeAllowd(ArchiveEntry entry){
- String entryName = entry.getName();
- for(String entryType : entryTypes){
- if(entryName.endsWith(entryType))
- return true;
- }
- return false;
- }
-}
\ No newline at end of file
+ public ArchiveFileExtractor(String[] entryTypes) {
+ this.entryTypes = entryTypes;
+ }
+
+ public List<Picture> extractArchive(InputStream inStream) {
+ ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
+ List<Picture> pictures = new ArrayList<Picture>();
+ try {
+ ArchiveInputStream archiveInputStream = streamFactory.createArchiveInputStream(inStream);
+ ArchiveEntry entry = null;
+ while ((entry = archiveInputStream.getNextEntry()) != null) {
+ if (!entry.isDirectory() && isEntryTypeAllowd(entry)) {
+ byte buf[] = IOUtils.toByteArray(archiveInputStream);
+ InputStream inputStream = new ByteArrayInputStream(buf);
+ Picture picture = new Picture(entry.getName(), new Date(), inputStream);
+ pictures.add(picture);
+ }
+ }
+ } catch (ArchiveException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return pictures;
+ }
+
+ /**
+ * Test whether this stream is of archive type or not
+ *
+ * @param inStream InputStream
+ * @return boolean
+ */
+ public boolean isArchive(InputStream inStream) {
+ ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
+ try {
+ streamFactory.createArchiveInputStream(inStream);
+ return true;
+ } catch (ArchiveException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
+ * Test weather the extension of given entry is allowed or not
+ *
+ * @param entry ArchiveEntry
+ * @return boolean
+ */
+ private boolean isEntryTypeAllowd(ArchiveEntry entry) {
+ String entryName = entry.getName();
+ for (String entryType : entryTypes) {
+ if (entryName.endsWith(entryType))
+ return true;
+ }
+ return false;
+ }
+}
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/FileUploader.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/FileUploader.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/FileUploader.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/FileUploader.java Sun Feb 14 05:03:02 2010
@@ -30,45 +30,41 @@
import org.apache.photark.Picture;
public class FileUploader {
-
- private String entryTypes [] = {".jpg",".jpeg",".png",".gif"};
-
- public FileUploader(){
- }
-
-
- public List<Picture> uploadFile(InputStream inStream, String fileName) throws IOException{
-
- List<Picture> pictures = new ArrayList<Picture>();
-
- if(isArchive(inStream)){
- ArchiveFileExtractor archiveFileExtractor = new ArchiveFileExtractor(entryTypes);
- pictures = archiveFileExtractor.extractArchive(inStream);
- }
- else{
- // this is a picture file and not the archive file
- Picture picture = new Picture(fileName, new Date(), inStream);
- pictures.add(picture);
- }
- return pictures;
- }
-
-
- /**
- * Test whether this stream is of archive or not
- *
- * @param inStream InputStream
- *
- * @return boolean
- */
- public boolean isArchive(InputStream inStream){
- ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
- try {
- streamFactory.createArchiveInputStream(inStream);
- return true;
- } catch (ArchiveException e) {
- e.printStackTrace();
- }
- return false;
- }
-}
\ No newline at end of file
+
+ private String entryTypes[] = {".jpg", ".jpeg", ".png", ".gif"};
+
+ public FileUploader() {
+ }
+
+ public List<Picture> uploadFile(InputStream inStream, String fileName) throws IOException {
+
+ List<Picture> pictures = new ArrayList<Picture>();
+
+ if (isArchive(inStream)) {
+ ArchiveFileExtractor archiveFileExtractor = new ArchiveFileExtractor(entryTypes);
+ pictures = archiveFileExtractor.extractArchive(inStream);
+ } else {
+ // this is a picture file and not the archive file
+ Picture picture = new Picture(fileName, new Date(), inStream);
+ pictures.add(picture);
+ }
+ return pictures;
+ }
+
+ /**
+ * Test whether this stream is of archive or not
+ *
+ * @param inStream InputStream
+ * @return boolean
+ */
+ public boolean isArchive(InputStream inStream) {
+ ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
+ try {
+ streamFactory.createArchiveInputStream(inStream);
+ return true;
+ } catch (ArchiveException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+}
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/PhotoUploadServlet.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/PhotoUploadServlet.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/PhotoUploadServlet.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/upload/PhotoUploadServlet.java Sun Feb 14 05:03:02 2010
@@ -39,85 +39,80 @@
import org.apache.photark.services.album.Album;
import org.apache.photark.services.album.jcr.AlbumImpl;
-public class PhotoUploadServlet extends HttpServlet
-{
- private static final long serialVersionUID = 1L;
- public static final long MAX_UPLOAD_ZIP_IN_MEGS = 30;
-
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
- doPost(request, response);
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
- response.setContentType("text/html");
-
- boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
- if (!isMultipartContent) {
- return;
- }
-
- FileItemFactory factory = new DiskFileItemFactory();
- ServletFileUpload upload = new ServletFileUpload(factory);
- upload.setSizeMax(MAX_UPLOAD_ZIP_IN_MEGS * 1024 * 1024);
-
- try {
- List<FileItem> fields = upload.parseRequest(request);
- System.out.println("Number of fields: " + fields.size());
- Iterator<FileItem> it = fields.iterator();
-
- if (!it.hasNext()) {
- System.out.println("No fields found");
- return;
- }
-
- String albumName = "";
- StringBuffer sb = new StringBuffer();
- while (it.hasNext()) {
- FileItem fileItem = it.next();
-
- if(fileItem.getFieldName().equalsIgnoreCase("albumname")){
- albumName = fileItem.getString();
- }
- boolean isFormField = fileItem.isFormField();
-
- if(!isFormField)
- {
- String fileName = fileItem.getName();
-
- InputStream inStream = fileItem.getInputStream();
-
- FileUploader uploader = new FileUploader();
- List<Picture> pictures = uploader.uploadFile(new BufferedInputStream(inStream), fileName);
-
- for(Picture picture :pictures){
- addPictureToAlbum(albumName, picture);
- }
- sb.append("file=uploaded/" + fileName);
- sb.append(",name="+fileName);
- sb.append(",error=Not recognized file type");
- }
- }
- PrintWriter out = response.getWriter();
- out.write(sb.toString());
-
- } catch (FileUploadException e) {
- System.out.println("Error: " + e.getMessage());
- e.printStackTrace();
- }
- catch (Exception e) {
- System.out.println("Error: " + e.getMessage());
- e.printStackTrace();
- }
- }
-
-
- /**
- *
- * @param albumName String
- * @param picture Picture
- */
- private void addPictureToAlbum(String albumName, Picture picture){
- Album album = new AlbumImpl(albumName);
- album.addPicture(picture);
- }
-}
\ No newline at end of file
+public class PhotoUploadServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+ public static final long MAX_UPLOAD_ZIP_IN_MEGS = 30;
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ doPost(request, response);
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ response.setContentType("text/html");
+
+ boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
+ if (!isMultipartContent) {
+ return;
+ }
+
+ FileItemFactory factory = new DiskFileItemFactory();
+ ServletFileUpload upload = new ServletFileUpload(factory);
+ upload.setSizeMax(MAX_UPLOAD_ZIP_IN_MEGS * 1024 * 1024);
+
+ try {
+ List<FileItem> fields = upload.parseRequest(request);
+ System.out.println("Number of fields: " + fields.size());
+ Iterator<FileItem> it = fields.iterator();
+
+ if (!it.hasNext()) {
+ System.out.println("No fields found");
+ return;
+ }
+
+ String albumName = "";
+ StringBuffer sb = new StringBuffer();
+ while (it.hasNext()) {
+ FileItem fileItem = it.next();
+
+ if (fileItem.getFieldName().equalsIgnoreCase("albumname")) {
+ albumName = fileItem.getString();
+ }
+ boolean isFormField = fileItem.isFormField();
+
+ if (!isFormField) {
+ String fileName = fileItem.getName();
+
+ InputStream inStream = fileItem.getInputStream();
+
+ FileUploader uploader = new FileUploader();
+ List<Picture> pictures = uploader.uploadFile(new BufferedInputStream(inStream), fileName);
+
+ for (Picture picture : pictures) {
+ addPictureToAlbum(albumName, picture);
+ }
+ sb.append("file=uploaded/" + fileName);
+ sb.append(",name=" + fileName);
+ sb.append(",error=Not recognized file type");
+ }
+ }
+ PrintWriter out = response.getWriter();
+ out.write(sb.toString());
+
+ } catch (FileUploadException e) {
+ System.out.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ } catch (Exception e) {
+ System.out.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * @param albumName String
+ * @param picture Picture
+ */
+ private void addPictureToAlbum(String albumName, Picture picture) {
+ Album album = new AlbumImpl(albumName);
+ album.addPicture(picture);
+ }
+}
Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/Picture.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/Picture.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/Picture.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/Picture.java Sun Feb 14 05:03:02 2010
@@ -28,34 +28,33 @@
* Model representing an album image
*/
public class Picture {
- private String name;
- private String description;
- private Date creationDate;
- private InputStream inStream;
-
- private List<Properties> imageProperties;
-
- public Picture(String name, Date createDate){
- this.name = name;
- this.creationDate = createDate;
- }
-
- public Picture(String name, Date createDate, InputStream inStream){
- this(name, createDate);
- this.inStream = inStream;
- }
-
-
- public String getName(){
- return name;
- }
-
- public Date getCreationDate(){
- return creationDate;
- }
-
- public InputStream getInputStream(){
- return inStream;
- }
-
-}
\ No newline at end of file
+ private String name;
+ private String description;
+ private Date creationDate;
+ private InputStream inStream;
+
+ private List<Properties> imageProperties;
+
+ public Picture(String name, Date createDate) {
+ this.name = name;
+ this.creationDate = createDate;
+ }
+
+ public Picture(String name, Date createDate, InputStream inStream) {
+ this(name, createDate);
+ this.inStream = inStream;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ public InputStream getInputStream() {
+ return inStream;
+ }
+
+}
Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/ImageDisplayer.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/ImageDisplayer.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/ImageDisplayer.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/ImageDisplayer.java Sun Feb 14 05:03:02 2010
@@ -23,8 +23,8 @@
import org.apache.tuscany.sca.data.collection.Collection;
import org.oasisopen.sca.annotation.Remotable;
+
@Remotable
-public interface ImageDisplayer extends Collection<String, InputStream>
-{
+public interface ImageDisplayer extends Collection<String, InputStream> {
-}
\ No newline at end of file
+}
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=909970&r1=909969&r2=909970&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 Feb 14 05:03:02 2010
@@ -91,10 +91,10 @@
}
public void addPicture(Picture picture){
-
+ throw new UnsupportedOperationException("Not implemented");
}
public void deletePicture(Picture picture){
-
+ throw new UnsupportedOperationException("Not implemented");
}
}
\ No newline at end of file
Modified: incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/AbsGalleryImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/AbsGalleryImpl.java?rev=909970&r1=909969&r2=909970&view=diff
==============================================================================
--- incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/AbsGalleryImpl.java (original)
+++ incubator/photark/trunk/photark/src/main/java/org/apache/photark/services/gallery/AbsGalleryImpl.java Sun Feb 14 05:03:02 2010
@@ -22,93 +22,91 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.photark.Picture;
import org.apache.photark.services.album.Album;
import org.oasisopen.sca.annotation.Property;
public abstract class AbsGalleryImpl implements Gallery {
-
- protected String name;
- private String location;
- protected boolean initialized;
- protected List<Album> albums = new ArrayList<Album>();
-
- public AbsGalleryImpl() {
-
- }
-
- public AbsGalleryImpl(String name) {
- this.name = name;
- }
-
- public abstract void init();
-
- public String getName() {
- return name;
- }
-
- @Property
- public void setName(String name) {
- this.name = name;
- }
-
- public void addAlbum(Album album) {
-
- }
-
- public Album[] getAlbums() {
- if(! initialized) {
- init();
- }
-
- Album[] albumArray = new Album[albums.size()];
- albums.toArray(albumArray);
- return albumArray;
- }
-
- public String getAlbumCover(String albumName) {
- Album albumLookup = getAlbum(albumName);
-
- if (albumLookup != null) {
- String [] pictures = albumLookup.getPictures();
- // this check is to avoid Exception
- if(pictures.length > 0){
- return albumLookup.getPictures()[0];
- }
- else{
- System.out.println("No Album Cover Picture found for album:"+albumName);
- return null;
- }
- } 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() {
- return location;
- }
+
+ protected String name;
+ private String location;
+ protected boolean initialized;
+ protected List<Album> albums = new ArrayList<Album>();
+
+ public AbsGalleryImpl() {
+
+ }
+
+ public AbsGalleryImpl(String name) {
+ this.name = name;
+ }
+
+ public abstract void init();
+
+ public String getName() {
+ return name;
+ }
+
+ @Property
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void addAlbum(Album album) {
+
+ }
+
+ public Album[] getAlbums() {
+ if (!initialized) {
+ init();
+ }
+
+ Album[] albumArray = new Album[albums.size()];
+ albums.toArray(albumArray);
+ return albumArray;
+ }
+
+ public String getAlbumCover(String albumName) {
+ Album albumLookup = getAlbum(albumName);
+
+ if (albumLookup != null) {
+ String[] pictures = albumLookup.getPictures();
+ // this check is to avoid Exception
+ if (pictures.length > 0) {
+ return albumLookup.getPictures()[0];
+ } else {
+ System.out.println("No Album Cover Picture found for album:" + albumName);
+ return null;
+ }
+ } 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() {
+ return location;
+ }
}