JBoss.org Community Documentation
This example consists of a client application that sets up an in-memory JCR repository and that allows a user to upload files into that repository. The client also sets up the DNA services with two sequencers so that if any of the uploaded files are PNG, JPEG, GIF, BMP or other images, DNA will automatically extract the image's metadata (e.g., image format, physical size, pixel density, etc.) and store that in the repository. Alternatively, if the uploaded file is an MP3 audio file, DNA will extract some of the ID3 metadata (e.g., the author, title, album, year and comment) and store that in the repository.
To run the client application, go to the
examples/sequencers/target/dna-example-sequencers-basic.dir/
directory and type
./run.sh
. You should see the command-line client and its menus in your terminal:
From this menu, you can upload a file into the repository, search for media in the repository, print sequencing statistics,
or quit the application.
The first step is to upload one of the example images. If you type 'u' and press return, you'll be prompted to supply the
path to the file you want to upload. Since the application is running from within the
examples/sequencers/target/dna-example-sequencers-basic.dir/
directory, you can specify any of the files in that directory without specifying the path:
You can specify any fully-qualified or relative path. The application will notify you if it cannot find the file you
specified. The example client configures JBoss DNA to sequence and MP3 audio files and image files with one of
the following extensions (technically, nodes that have names ending in the following):
jpg
,
jpeg
,
gif
,
bmp
,
pcx
,
png
,
iff
,
ras
,
pbm
,
pgm
,
ppm
, and
psd
. Files with other extensions in the repository path will be ignored. For your convenience, the example provides several
files that will be sequenced (
caution.png
,
caution.jpg
,
caution.gif
, and
sample1.mp3
) and one image that will not be sequenced (
caution.pict
). Feel free to try other files.
After you have specified the file you want to upload, the example application asks you where in the repository you'd like to
place the file. (If you want to use the suggested location, just press
return
.) The client application uses the JCR API to upload the file to that location in the repository, creating any nodes (of
type
nt:folder
) for any directories that don't exist, and creating a node (of type
nt:file
) for the file. And, per the JCR specification, the application creates a
jcr:content
node (of type
nt:resource
) under the file node. The file contents are placed on this
jcr:content
node in the
jcr:data
property. For example, if you specify
/a/b/caution.png
, the following structure will be created in the repository:
/a (nt:folder) /b (nt:folder) /caution.png (nt:file) /jcr:content (nt:resource) @jcr:data = {contents of the file} @jcr:mimeType = {mime type of the file} @jcr:lastModified = {now}
Other kinds of files are treated in a similar way.
When the client uploads the file using the JCR API, DNA gets notified of the changes, consults the sequencers to see whether
any of them are interested in the new or updated content, and if so runs those sequencers. The image sequencer processes image
files for metadata, and any metadata found is stored under the
/images
branch of the repository. The MP3 sequencer processes MP3 audio files for metadata, and any metadata found is stored under the
/mp3s
branch of the repository. All of this happens asynchronously, so any DNA activity doesn't impede or slow down the client
activities.
So, after the file is uploaded, you can search the repository for the image metadata using the "s" menu option:
Here are the search results after the sample1.mp3
audio file has been uploaded (to the /a/b/sample1.mp3
location):
You can also display the sequencing statistics using the "d" menu option:
These stats show how many nodes were sequenced, and how many nodes were skipped because they didn't apply to the sequencer's
criteria.
There will probably be more nodes skipped than sequenced, since there are more
nt:folder
and
nt:resource
nodes than there are
nt:file
nodes with acceptable names.
You can repeat this process with other files. Any file that isn't an image or MP3 files (as recognized by the sequencing configurations that we'll describe later) will not be sequenced.