cbr.service
Class PictureDB

java.lang.Object
  extended byde.fhg.igd.semoa.service.AbstractService
      extended bycbr.service.PictureDB
All Implemented Interfaces:
PicsSource, Service

public class PictureDB
extends AbstractService
implements PicsSource

A class which implements the service that is used to advertise the pictures.

This class provides an iterator for the pictures in the configured picture directory. This iterator attempts to open and read line by line a file with the name " ls.txt" in the picture directory. This file must contain the names of the known pictures. Such a file can be created simply by issuing the command ls >ls.txt in the picture directory.

Iterating through the picture names and loading pictures requires that this class has privileges to read said files and that the reading instance is created by a class that has said privileges also. Malicious code can not create an instance of this class and exploit it to access said directories. See AbstractService for details.

Be careful, this class contains a security hole that might allow untrusted code to delete files!

Version:
"$Id: PictureDB.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth
See Also:
PrivilegedOpen, Service

Field Summary
protected  File pictures_
          The directory from which pictures are loaded.
protected  File thumbnails_
          The directory from which thumbnails are loaded.
 
Fields inherited from class de.fhg.igd.semoa.service.AbstractService
REV_POSTFIX, REV_PREFIX
 
Constructor Summary
PictureDB()
          Creates an instance.
PictureDB(File p, File t)
          Creates an instance which loads images from the given directories.
 
Method Summary
 String author()
          Returns the name of the author of the service.
 byte[] getPicture(String name)
          Retrieves a picture based on the name.
 byte[] getThumbnail(String name)
          Retrieves a thumbnail based on the name.
 String info()
          Returns the informative string which should describe the service's essence in a sentence.
 Iterator iterator()
          Returns an iterator that iterates the names of the available pictures.
private  byte[] loadPicture(File file)
          Loads a file into a byte array.
 String revision()
          Returns the revision number of this class as a string.
 void setPictures(File file)
           
 void setThumbnails(File file)
           
 
Methods inherited from class de.fhg.igd.semoa.service.AbstractService
checkDependencies, dependencies, docs, doPrivileged, doPrivileged, getACC, getEnvironment, majorVersion, minorVersion, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pictures_

protected File pictures_
The directory from which pictures are loaded.


thumbnails_

protected File thumbnails_
The directory from which thumbnails are loaded.

Constructor Detail

PictureDB

public PictureDB()
Creates an instance.


PictureDB

public PictureDB(File p,
                 File t)
Creates an instance which loads images from the given directories. For each image there should be a thumbnail available. Thumbnails must have the same name as the picture to which they refer.

Parameters:
p - The directory containing the available pictures.
t - The directory containing the thumbnails for the available pictures.
Method Detail

author

public String author()
Description copied from class: AbstractService
Returns the name of the author of the service. The format to be used should be John Doe <jdoe@zilch.net>.

Specified by:
author in interface Service
Specified by:
author in class AbstractService
Returns:
the String with the author's name.

revision

public String revision()
Description copied from class: AbstractService
Returns the revision number of this class as a string. This class provides default implementations of methods majorVersion(), minorVersion based on the assumption that this method returns a revision string as generated by rcs(1) for the template "$Revision: 1.7 $/$Date: 2007-08-08 04:41:53 +0200 (Wed, 08 Aug 2007) $".

Specified by:
revision in class AbstractService

info

public String info()
Description copied from class: AbstractService
Returns the informative string which should describe the service's essence in a sentence.

Specified by:
info in interface Service
Specified by:
info in class AbstractService
Returns:
the String with the service's short description.

setPictures

public void setPictures(File file)

setThumbnails

public void setThumbnails(File file)

iterator

public Iterator iterator()
Returns an iterator that iterates the names of the available pictures.

Specified by:
iterator in interface PicsSource
Returns:
The iterator that iterates the names of the available pictures..

getPicture

public byte[] getPicture(String name)
Retrieves a picture based on the name.

Specified by:
getPicture in interface PicsSource
Parameters:
name - The name of the picture. This name must be locally unique.
Returns:
The encoding of the picture with the given name.

getThumbnail

public byte[] getThumbnail(String name)
Retrieves a thumbnail based on the name.

Specified by:
getThumbnail in interface PicsSource
Parameters:
name - The name of the picture. This name must be locally unique.
Returns:
The encoding of the picture with the given name.

loadPicture

private byte[] loadPicture(File file)
Loads a file into a byte array. This method is used for loading pictures and thumbnails from folders to which access is restricted.

Parameters:
file - The file to load.
Returns:
The bytes of the file.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.