[greenstone-devel] Re: About writing code to retrive images

From Anupama of Greenstone Team
DateWed Aug 20 18:28:36 2008
Subject [greenstone-devel] Re: About writing code to retrive images
In-Reply-To (48AAF3B4-3040802-cis-strath-ac-uk)
Hi Suthanya,
> Or i should study the code "LibraryServlet.java" because when i
> run classic libray it will show search and browse function.
It's always good to gain a better understanding of GS3 by inspecting code.

The democlient's code just got the html for each document which already
contained the (resolved) <img src="location"> values. However, if you
want to obtain just the images for display elsewhere, then they way I'd
go about this is to get the metadata for the src link of images.

1. I don't remember off the top of my head what this is, I think it is
srclink, but don't rely on that. You can find out what the metadata is
called, by sending a request to the MessageRouter to get all the
metadata of a document that you know is an image or, if it's an html,
that it contains images. You can try going through the QBRSOAPServer to
do the above, by calling its "retrieveAllDocumentMetadata" web service
for the document(s) you want.

2. Once you get back all the metadata of such a document, look at the
response xml to see which of the metadata is the image's src link. You
can confirm this by opening up a browser and going to your greenstone
collection and viewing that image.

3. Now that you know the metadata name to retrieve to get the image src
link, you can write code that no longer gets *all* the metadata, but
just the metadata that gives you the src link.

Knowing name of the metadata item that you want, you can call the
"retrieveDocumentMetadata" web service operation of QBRSOAPServer,
passing in the name(s) of the metadata element(s) you want - such as
"srclink" or "Title".

If you plan on using the QBRSOAPServer, you may wish to include the
intermediate client-side class I wrote for it by including the package
dlservices (at
and also in your copy of the democlient. It's easiest to include the
executable jar file in your build path and do
import org.greenstone.gs3client.dlservices.*;

Then you can create an object of class
org.greenstone.gs3client.dlservices.GS3ServicesAPIA and use it to call
the web services operations:

// the GS3ServicesAPIA is the class that connects to and invokes
// the QBRSOAPServer's web services
GS3ServicesAPIA gs3APIA = new GS3ServicesAPIA();

// then call the methods of QBRSOAPServer you want
// print the responses to the screen, e.g.
String response = gs3APIA.describe();
System.out.println("describe returned:\n" + response);

response = gs3APIA.retrieveAllDocumentMetadata(collection, language,
// collection is the name of the collection you are querying,
// language will be "en" I think. Whatever languages the MessageRouter
// accepts and finally, docIDs is an array of Strings of the document
// identifiers (hashIDs) for which you want to retrieve the metadata.
System.out.println("Response from allDocMeta request:\n" + response);

// Once you know the name of the metadata you want, you can call it as:
final String[] myMetaName = {"srclink"}; // whatever the name is for img

response = gs3APIA.retrieveDocumentMetadata(collection, language,
docIDs, myMetaName);
// The above will have retrieved the srclink meta for all the documents
// you specified

System.out.println("Response when requesting " + myMetaName + ":\n" +

// Now parse the xml response to get the value for the srclink/other
// metadata
...parse XML

Look at this class to see how it uses the "dlAPIA" (similar to gs3APIA,
but it calls on methods that GS3ServicesAPIA implements for the
interface DigitalLibraryServicesAPIA):


Suthanya Doung-In wrote:
> Dear Anupama,
> I would like to ask you about how to writing code to retrieve images
> for showing in web page. If possible, i would like to try adding some
> function such as comment or rating an image in collection. It 's like
> amazon.com. My digital library is image and text collection. Could you
> suggest me roughly about this please. It make me see the direction how
> to develop it more clearly.
> Or i should study the code "LibraryServlet.java" because when i run
> classic libray it will show search and browse function.
> Best Wishes,
> Suthanya Doung-in