Rakesh API

org.rakeshv.xml.album
Class PhotoAlbum

java.lang.Object
  extended by org.rakeshv.xml.album.PhotoAlbum

public class PhotoAlbum
extends java.lang.Object

Photo album implementation. This class presents a java view of the specified album xml file. This class also contains methods for creating new album entries, and for deleted existing entries.

You can use the createPhotoAlbum( String ) method to create a new photo album specified by the fully qualified file name specified in the method call.

© Copyright 2003 Rakesh Vidyadharan

Version:
$Id: PhotoAlbum.java,v 1.3 2004/10/16 19:17:02 rakesh Exp $
Author:
Rakesh Vidyadharan 2003 October 31

Field Summary
private  java.util.Map albums
          The map of Album records.
private  org.jdom.Document document
          A reference to the album XML document.
private  java.lang.String fileName
          The fully qualified name of the album XML file.
private  org.jdom.Namespace namespace
          The namespace for the root element.
private  org.jdom.Element rootElement
          The root element of the XML file.
 
Constructor Summary
protected PhotoAlbum()
          Default constructor.
  PhotoAlbum(java.lang.String fileName)
          Just invoke PhotoAlbum( String, String ) with a value of null for the preferred SAX Parser to use.
  PhotoAlbum(java.lang.String fileName, java.lang.String saxParser)
          Load the specified album XML file using the specified SAX Parser.
 
Method Summary
 void addAlbum(Album album)
          Add the specified Album java bean to the albums map.
private  void addAlbumToTree(Album album)
          Add the specified Album object to the JDOM tree as a album element.
private  void addImageToTree(org.jdom.Element element, java.lang.String name, Image image)
          Add the specified Image object to the specified element as an element with the name specified.
private  void addPhotoToTree(org.jdom.Element element, Album album)
          Add all the Photo beans in the Album specified to the Element passed in.
static PhotoAlbum createPhotoAlbum(java.lang.String file)
          Just invokes createPhotoAlbum( String, String ) with a null value for the default SAX Parser.
static PhotoAlbum createPhotoAlbum(java.lang.String file, java.lang.String saxParser)
          Create a new album using the fully qualified file name specified, and using the specified SAX Parser to load the XML file that has been created.
 boolean deleteAlbum(java.lang.String name)
          Remove the Album identified by the specified Album.name.
 boolean deleteAlbums(java.lang.String[] names)
          Remove the Album's identified by the specified Album.names.
 java.util.Map getAlbums()
          Return the value/reference of the albums.
 java.lang.String getFileName()
          Returns fileName.
private  void loadAlbums(java.lang.String saxParser)
          Load the album XML file (fileName) using JDOM, and populate the albums class field.
 void modifyAlbum(Album album)
          Save the specified Album java bean that has been modified to the underlying JDOM tree.
private  Album populateAlbum(org.jdom.Element element)
          Walk through the child elements of the specified album element, and create a corresponding Album bean.
private  void populateAlbums()
          Walk through the JDOM tree, and populate the albums Map of Album objects.
private  Image populateImage(org.jdom.Element element)
          Return a Image java bean with the data from the specified Element of type image.
private  Photo populatePhoto(org.jdom.Element element)
          Create a Photo java bean instance with all the data from the specified photo element.
 void saveAlbums()
          Write the JDOM tree back to the album file.
 void setFileName(java.lang.String fileName)
          Set fileName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileName

private java.lang.String fileName
The fully qualified name of the album XML file.


albums

private java.util.Map albums
The map of Album records. This corresponds to all the album elements under the albums element in the photo album. The map is populated using the Album.name as the key.


document

private org.jdom.Document document
A reference to the album XML document.


rootElement

private org.jdom.Element rootElement
The root element of the XML file.


namespace

private org.jdom.Namespace namespace
The namespace for the root element.

Constructor Detail

PhotoAlbum

protected PhotoAlbum()
Default constructor. Cannot be directly called.


PhotoAlbum

public PhotoAlbum(java.lang.String fileName)
           throws AlbumException
Just invoke PhotoAlbum( String, String ) with a value of null for the preferred SAX Parser to use.

Parameters:
fileName - - The fully qualified name of the photo album XML file.
Throws:
AlbumException - - If any JDOM/IOExceptions are encountered while processing the album XML file.

PhotoAlbum

public PhotoAlbum(java.lang.String fileName,
                  java.lang.String saxParser)
           throws AlbumException
Load the specified album XML file using the specified SAX Parser.

Parameters:
fileName - - The fully qualified name of the photo album XML file.
saxParser - - The full class name of the preferred SAX Parser to use.
Throws:
AlbumException - - If any JDOM/IOExceptions are encountered while processing the album XML file.
See Also:
loadAlbums( String )
Method Detail

loadAlbums

private void loadAlbums(java.lang.String saxParser)
                 throws AlbumException
Load the album XML file (fileName) using JDOM, and populate the albums class field.

Parameters:
saxParser - - The full class name of the SAX Parser to use. If this is null the default JAXP SAX Parser will be used.
Throws:
AlbumException - - If any JDOM/IOExceptions are encountered while processing the album XML file.
See Also:
populateAlbums()

populateAlbums

private void populateAlbums()
Walk through the JDOM tree, and populate the albums Map of Album objects. Fetches all the children of the rootElement root Element in the album XML file.

See Also:
populateAlbum( Element )

populateAlbum

private Album populateAlbum(org.jdom.Element element)
Walk through the child elements of the specified album element, and create a corresponding Album bean.

Parameters:
element - - The current album element.
Returns:
Album - The java bean that was created with the child elements of the specified album element.
See Also:
populatePhoto( Element )

populatePhoto

private Photo populatePhoto(org.jdom.Element element)
Create a Photo java bean instance with all the data from the specified photo element.

Parameters:
element - - The current photo element.
Returns:
Photo - The java bean that was created with the child elements of the specified photo element.
See Also:
populateImage( Element )

populateImage

private Image populateImage(org.jdom.Element element)
Return a Image java bean with the data from the specified Element of type image.

Parameters:
element - - The current image element.
Returns:
Album - The java bean that was created with the child elements of the specified image element.

addAlbum

public void addAlbum(Album album)
              throws AlbumException
Add the specified Album java bean to the albums map. This method checks to make sure that an entry with the same Album.name does not exist in the albums Map. The specified Album object is added both to the albums Map, as well as to the JDOM tree.

Note:This method does not write the modified JDOM tree back to the album file. To save your modifications, please use the saveAlbums() method.

Parameters:
album - - The java bean with all the information pertaining to a album entry in the photo album.
Throws:
AlbumException - - If the specified Album has an identical Album.name as an existing entry in the albums Map.
See Also:
addAlbumToTree( Album )

modifyAlbum

public void modifyAlbum(Album album)
Save the specified Album java bean that has been modified to the underlying JDOM tree. The easiest way to do this is to remove the existing album element, and add the modified Album bean as a new child element of the albums element using addAlbumToTree( Album ).

Note:This method does not write the modified JDOM tree back to the album file. To save your modifications, please use the saveAlbums() method.

Parameters:
album - - The java bean with all the information pertaining to a album entry in the album.
See Also:
addAlbumToTree( Album )

addAlbumToTree

private void addAlbumToTree(Album album)
Add the specified Album object to the JDOM tree as a album element.

Note:This method does not write the modified JDOM tree back to the album file. To save your modifications, please use the saveAlbums() method.

Parameters:
album - - The java bean with all the information pertaining to a album entry in the album.

addPhotoToTree

private void addPhotoToTree(org.jdom.Element element,
                            Album album)
Add all the Photo beans in the Album specified to the Element passed in. Walk through the Album.photos map and add each instance to the XML tree.

Parameters:
element - - The XML element to which the photos are to be added.
album - - The album instance from which the photos are to be added.

addImageToTree

private void addImageToTree(org.jdom.Element element,
                            java.lang.String name,
                            Image image)
Add the specified Image object to the specified element as an element with the name specified.

Parameters:
element - - The parent element to which the image element is to be added.
name - - The name to use for the image element that will be added to the parent.
image - - The image java bean to be used to populate the image element children.

deleteAlbums

public boolean deleteAlbums(java.lang.String[] names)
Remove the Album's identified by the specified Album.names. This method removes the Album's from the albums Map as well as the appropriate element from the underlying JDOM tree. This method just iterates through the array, and invokes deleteAlbum( String ) to delete each Album specified.

Parameters:
names - - The names of the album that are to be removed.
Returns:
boolean - Returns true if the name exists in the albums Map, and false otherwise. A return value of false indicates that not all the specified albums could be deleted, as not all of them were valid.

deleteAlbum

public boolean deleteAlbum(java.lang.String name)
Remove the Album identified by the specified Album.name. This method removes the Album from the albums Map as well as the appropriate element from the underlying JDOM tree.

Parameters:
name - - The name of the album that is to be removed.
Returns:
boolean - Returns true if the name exists in the albums Map, and false otherwise.

saveAlbums

public void saveAlbums()
                throws AlbumException
Write the JDOM tree back to the album file.

Throws:
AlbumException - - If any exceptions are encountered while serialising the JDOM tree to the album file.

createPhotoAlbum

public static PhotoAlbum createPhotoAlbum(java.lang.String file)
                                   throws AlbumException
Just invokes createPhotoAlbum( String, String ) with a null value for the default SAX Parser.

Parameters:
file - - The fully qualified name of the file ie. the full path and name of file to use as the album.
Throws:
AlbumException - - If any exceptions are encountered while creating or writing to the specified file.

createPhotoAlbum

public static PhotoAlbum createPhotoAlbum(java.lang.String file,
                                          java.lang.String saxParser)
                                   throws AlbumException
Create a new album using the fully qualified file name specified, and using the specified SAX Parser to load the XML file that has been created.

Parameters:
file - - The fully qualified name of the file ie. the full path and name of file to use as the album.
saxParser - - The full class name of the preferred SAX Parser. If this is null the default JAXP SAX Parser will be used.
Throws:
AlbumException - - If any exceptions are encountered while creating or writing to the specified file.

getAlbums

public final java.util.Map getAlbums()
Return the value/reference of the albums.

Returns:
Map - The value/reference of albums.

getFileName

public final java.lang.String getFileName()
Returns fileName.

Returns:
String - The value/reference of/to fileName.

setFileName

public final void setFileName(java.lang.String fileName)
Set fileName.

Parameters:
fileName - - The value to set.

Rakesh API

Copyright © 2002-2005 - Rakesh Vidyadharan