KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > jsptag > ItemTag


1 /*
2  * ItemTag.java
3  *
4  * Version: $Revision: 1.44 $
5  *
6  * Date: $Date: 2006/11/28 04:15:35 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.app.webui.jsptag;
41
42 import org.apache.log4j.Logger;
43 import org.dspace.app.webui.util.UIUtil;
44
45 import org.dspace.content.Bitstream;
46 import org.dspace.content.Bundle;
47 import org.dspace.content.Collection;
48 import org.dspace.content.DCDate;
49 import org.dspace.content.DCValue;
50 import org.dspace.content.Item;
51
52 import org.dspace.core.ConfigurationManager;
53 import org.dspace.core.Constants;
54 import org.dspace.core.Utils;
55
56 import java.io.IOException JavaDoc;
57
58 import java.sql.SQLException JavaDoc;
59 import java.util.Enumeration JavaDoc;
60 import java.util.HashMap JavaDoc;
61 import java.util.Map JavaDoc;
62 import java.util.StringTokenizer JavaDoc;
63
64 import javax.servlet.http.HttpServletRequest JavaDoc;
65 import javax.servlet.jsp.JspException JavaDoc;
66 import javax.servlet.jsp.JspWriter JavaDoc;
67 import javax.servlet.jsp.jstl.fmt.LocaleSupport;
68 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
69
70 /**
71  * <P>
72  * JSP tag for displaying an item.
73  * </P>
74  * <P>
75  * The fields that are displayed can be configured in <code>dspace.cfg</code>
76  * using the <code>webui.itemdisplay.(style)</code> property. The form is
77  * </P>
78  *
79  * <PRE>
80  *
81  * &lt;schema prefix>.&lt;element&gt;[.&lt;qualifier&gt;|.*][(date)|(link)], ...
82  *
83  * </PRE>
84  *
85  * <P>
86  * For example:
87  * </P>
88  *
89  * <PRE>
90  *
91  * dc.title = Dublin Core element 'title' (unqualified) dc.title.alternative =
92  * DC element 'title', qualifier 'alternative' dc.title.* = All fields with
93  * Dublin Core element 'title' (any or no qualifier) dc.identifier.uri(link) =
94  * DC identifier.uri, render as a link dc.date.issued(date) = DC date.issued,
95  * render as a date
96  *
97  * </PRE>
98  *
99  * <P>
100  * If an item has no value for a particular field, it won't be displayed. The
101  * name of the field for display will be drawn from the current UI dictionary,
102  * using the key:
103  * </P>
104  *
105  * <PRE>
106  *
107  * "metadata.&lt;field&gt;"
108  *
109  * e.g. "metadata.dc.title" "metadata.dc.contributor.*"
110  * "metadata.dc.date.issued"
111  *
112  * </PRE>
113  *
114  * <P>
115  * You can also specify which collections use which views.
116  * </P>
117  *
118  * <PRE>
119  *
120  * webui.itemdisplay.&lt;style&gt;.collections = &lt;collection handle&gt;, ...
121  *
122  * </PRE>
123  *
124  * <P>
125  * FIXME: This should be more database-driven
126  * </P>
127  *
128  * <PRE>
129  *
130  * webui.itemdisplay.thesis.collections = 123456789/24, 123456789/35
131  *
132  * </PRE>
133  *
134  * @author Robert Tansley
135  * @version $Revision: 1.44 $
136  */

137 public class ItemTag extends TagSupport JavaDoc
138 {
139     /** Item to display */
140     private Item item;
141
142     /** Collections this item appears in */
143     private Collection[] collections;
144
145     /** The style to use - "default" or "full" */
146     private String JavaDoc style;
147
148     /** Whether to show preview thumbs on the item page */
149     private boolean showThumbs;
150
151     /** Hashmap of collection Handles to styles to use, from dspace.cfg */
152     private static Map JavaDoc collectionStyles;
153
154     /** Default DC fields to display, in absence of configuration */
155     private static String JavaDoc defaultFields = "dc.title, dc.title.alternative, dc.contributor.*, dc.subject, dc.date.issued(date), dc.publisher, dc.identifier.citation, dc.relation.ispartofseries, dc.description.abstract, dc.description, dc.identifier.govdoc, dc.identifier.uri(link), dc.identifier.isbn, dc.identifier.issn, dc.identifier.ismn, dc.identifier";
156
157     /** log4j logger */
158     private static Logger log = Logger.getLogger(ItemTag.class);
159
160     public ItemTag()
161     {
162         super();
163         getThumbSettings();
164         collectionStyles = null;
165     }
166
167     public int doStartTag() throws JspException JavaDoc
168     {
169         try
170         {
171             if (style == null || style.equals(""))
172             {
173                 // see if we need to use a particular style for a style
174
// FIXME?: Trust owning collection
175
Collection owner = item.getOwningCollection();
176                 if (owner != null)
177                 {
178                     getStyleFor(owner);
179                 }
180                 else
181                 {
182                     style = "default";
183                 }
184             }
185
186             if (style.equals("full"))
187             {
188                 renderFull();
189             }
190             else
191             {
192                 render();
193             }
194         }
195         catch (SQLException JavaDoc sqle)
196         {
197             throw new JspException JavaDoc(sqle);
198         }
199         catch (IOException JavaDoc ie)
200         {
201             throw new JspException JavaDoc(ie);
202         }
203
204         return SKIP_BODY;
205     }
206
207     /**
208      * Get the item this tag should display
209      *
210      * @return the item
211      */

212     public Item getItem()
213     {
214         return item;
215     }
216
217     /**
218      * Set the item this tag should display
219      *
220      * @param itemIn
221      * the item to display
222      */

223     public void setItem(Item itemIn)
224     {
225         item = itemIn;
226     }
227
228     /**
229      * Get the collections this item is in
230      *
231      * @return the collections
232      */

233     public Collection[] getCollections()
234     {
235         return collections;
236     }
237
238     /**
239      * Set the collections this item is in
240      *
241      * @param collectionsIn
242      * the collections
243      */

244     public void setCollections(Collection[] collectionsIn)
245     {
246         collections = collectionsIn;
247     }
248
249     /**
250      * Get the style this tag should display
251      *
252      * @return the style
253      */

254     public String JavaDoc getStyle()
255     {
256         return style;
257     }
258
259     /**
260      * Set the style this tag should display
261      *
262      * @param styleIn
263      * the Style to display
264      */

265     public void setStyle(String JavaDoc styleIn)
266     {
267         style = styleIn;
268     }
269
270     public void release()
271     {
272         style = "default";
273         item = null;
274         collections = null;
275     }
276
277     /**
278      * Render an item in the given style
279      */

280     private void render() throws IOException JavaDoc
281     {
282         JspWriter JavaDoc out = pageContext.getOut();
283
284         String JavaDoc configLine = ConfigurationManager
285                 .getProperty("webui.itemdisplay." + style);
286
287         if (configLine == null)
288             configLine = defaultFields;
289
290         out.println("<center><table class=\"itemDisplayTable\">");
291
292         /*
293          * Break down the configuration into fields and display them
294          *
295          * FIXME?: it may be more efficient to do some processing once, perhaps
296          * to a more efficient intermediate class, but then it would become more
297          * difficult to reload the configuration "on the fly".
298          */

299         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(configLine, ",");
300
301         while (st.hasMoreTokens())
302         {
303             String JavaDoc field = st.nextToken().trim();
304             boolean isDate = false;
305             boolean isLink = false;
306
307             // Find out if the field should rendered as a date or link
308

309             if (field.indexOf("(date)") > 0)
310             {
311                 field = field.replaceAll("\\(date\\)", "");
312                 isDate = true;
313             }
314
315             if (field.indexOf("(link)") > 0)
316             {
317                 field = field.replaceAll("\\(link\\)", "");
318                 isLink = true;
319             }
320             // Get the separate schema + element + qualifier
321

322             String JavaDoc[] eq = field.split("\\.");
323             String JavaDoc schema = eq[0];
324             String JavaDoc element = eq[1];
325             String JavaDoc qualifier = null;
326             if (eq.length > 2 && eq[2].equals("*"))
327             {
328                 qualifier = Item.ANY;
329             }
330             else if (eq.length > 2)
331             {
332                 qualifier = eq[2];
333             }
334             // FIXME: Still need to fix for metadata language?
335
DCValue[] values = item.getMetadata(schema, element, qualifier, Item.ANY);
336
337             if (values.length > 0)
338             {
339                 out.print("<tr><td class=\"metadataFieldLabel\">");
340
341                 out.print(LocaleSupport.getLocalizedMessage(pageContext,
342                         "metadata." + field));
343
344                 out.print(":&nbsp;</td><td class=\"metadataFieldValue\">");
345
346                 for (int j = 0; j < values.length; j++)
347                 {
348                     if (j > 0)
349                     {
350                         out.print("<br />");
351                     }
352
353                     if (isLink)
354                     {
355                         out.print("<a HREF=\"" + values[j].value + "\">"
356                                 + Utils.addEntities(values[j].value) + "</a>");
357                     }
358                     else if (isDate)
359                     {
360                         DCDate dd = new DCDate(values[j].value);
361
362                         // Parse the date
363
out.print(UIUtil.displayDate(dd, false, false));
364                     }
365                     else
366                     {
367                         out.print(Utils.addEntities(values[j].value));
368                     }
369                 }
370
371                 out.println("</td></tr>");
372             }
373         }
374
375         listCollections();
376
377         out.println("</table></center><br/>");
378
379         listBitstreams();
380
381         if (ConfigurationManager
382                 .getBooleanProperty("webui.licence_bundle.show"))
383
384         {
385             out.println("<br/><br/>");
386             showLicence();
387         }
388     }
389
390     /**
391      * Render full item record
392      */

393     private void renderFull() throws IOException JavaDoc
394     {
395         JspWriter JavaDoc out = pageContext.getOut();
396
397         // Get all the metadata
398
DCValue[] values = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
399
400         out.println("<p align=\"center\">"
401                 + LocaleSupport.getLocalizedMessage(pageContext,
402                         "org.dspace.app.webui.jsptag.ItemTag.full") + "</p>");
403
404         // Three column table - DC field, value, language
405
out.println("<center><table class=\"itemDisplayTable\">");
406         out.println("<tr><th id=\"s1\" class=\"standard\">"
407                 + LocaleSupport.getLocalizedMessage(pageContext,
408                         "org.dspace.app.webui.jsptag.ItemTag.dcfield")
409                 + "</th><th id=\"s2\" class=\"standard\">"
410                 + LocaleSupport.getLocalizedMessage(pageContext,
411                         "org.dspace.app.webui.jsptag.ItemTag.value")
412                 + "</th><th id=\"s3\" class=\"standard\">"
413                 + LocaleSupport.getLocalizedMessage(pageContext,
414                         "org.dspace.app.webui.jsptag.ItemTag.lang")
415                 + "</th></tr>");
416
417         for (int i = 0; i < values.length; i++)
418         {
419             boolean hidden = false;
420
421             // Mask description.provenance
422
if (values[i].element.equals("description")
423                     && ((values[i].qualifier != null) && values[i].qualifier
424                             .equals("provenance")))
425             {
426                 hidden = true;
427             }
428
429             if (!hidden)
430             {
431                 out
432                         .print("<tr><td headers=\"s1\" class=\"metadataFieldLabel\">");
433                 out.print(values[i].schema);
434                 out.print("." + values[i].element);
435
436                 if (values[i].qualifier != null)
437                 {
438                     out.print("." + values[i].qualifier);
439                 }
440
441                 out
442                         .print("</td><td headers=\"s2\" class=\"metadataFieldValue\">");
443                 out.print(Utils.addEntities(values[i].value));
444                 out
445                         .print("</td><td headers=\"s3\" class=\"metadataFieldValue\">");
446
447                 if (values[i].language == null)
448                 {
449                     out.print("-");
450                 }
451                 else
452                 {
453                     out.print(values[i].language);
454                 }
455
456                 out.println("</td></tr>");
457             }
458         }
459
460         listCollections();
461
462         out.println("</table></center><br/>");
463
464         listBitstreams();
465
466         if (ConfigurationManager
467                 .getBooleanProperty("webui.licence_bundle.show"))
468         {
469             out.println("<br/><br/>");
470             showLicence();
471         }
472     }
473
474     /**
475      * List links to collections if information is available
476      */

477     private void listCollections() throws IOException JavaDoc
478     {
479         JspWriter JavaDoc out = pageContext.getOut();
480         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext
481                 .getRequest();
482
483         if (collections != null)
484         {
485             out.print("<tr><td class=\"metadataFieldLabel\">");
486             if (item.getHandle()==null) // assume workspace item
487
{
488                 out.print(LocaleSupport.getLocalizedMessage(pageContext,
489                         "org.dspace.app.webui.jsptag.ItemTag.submitted"));
490             }
491             else
492             {
493                 out.print(LocaleSupport.getLocalizedMessage(pageContext,
494                           "org.dspace.app.webui.jsptag.ItemTag.appears"));
495             }
496             out.print("</td><td class=\"metadataFieldValue\">");
497
498             for (int i = 0; i < collections.length; i++)
499             {
500                 out.print("<a HREF=\"");
501                 out.print(request.getContextPath());
502                 out.print("/handle/");
503                 out.print(collections[i].getHandle());
504                 out.print("\">");
505                 out.print(collections[i].getMetadata("name"));
506                 out.print("</a><br/>");
507             }
508
509             out.println("</td></tr>");
510         }
511     }
512
513     /**
514      * List bitstreams in the item
515      */

516     private void listBitstreams() throws IOException JavaDoc
517     {
518         JspWriter JavaDoc out = pageContext.getOut();
519         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext
520                 .getRequest();
521
522         out.print("<table align=\"center\" class=\"miscTable\"><tr>");
523         out.println("<td class=\"evenRowEvenCol\"><p><strong>"
524                 + LocaleSupport.getLocalizedMessage(pageContext,
525                         "org.dspace.app.webui.jsptag.ItemTag.files")
526                 + "</strong></p>");
527
528         try
529         {
530             Bundle[] bundles = item.getBundles("ORIGINAL");
531
532             if (bundles.length == 0)
533             {
534                 out.println("<p>"
535                         + LocaleSupport.getLocalizedMessage(pageContext,
536                             "org.dspace.app.webui.jsptag.ItemTag.files.no")
537                             + "</p>");
538             }
539             else
540             {
541                 boolean html = false;
542                 String JavaDoc handle = item.getHandle();
543                 Bitstream primaryBitstream = null;
544
545                 Bundle[] bunds = item.getBundles("ORIGINAL");
546                 Bundle[] thumbs = item.getBundles("THUMBNAIL");
547
548                 // if item contains multiple bitstreams, display bitstream
549
// description
550
boolean multiFile = false;
551                 Bundle[] allBundles = item.getBundles();
552
553                 for (int i = 0, filecount = 0; (i < allBundles.length)
554                         && !multiFile; i++)
555                 {
556                     filecount += allBundles[i].getBitstreams().length;
557                     multiFile = (filecount > 1);
558                 }
559
560                 // check if primary bitstream is html
561
if (bunds[0] != null)
562                 {
563                     Bitstream[] bits = bunds[0].getBitstreams();
564
565                     for (int i = 0; (i < bits.length) && !html; i++)
566                     {
567                         if (bits[i].getID() == bunds[0].getPrimaryBitstreamID())
568                         {
569                             html = bits[i].getFormat().getMIMEType().equals(
570                                     "text/html");
571                             primaryBitstream = bits[i];
572                         }
573                     }
574                 }
575
576                 out
577                     .println("<table cellpadding=\"6\"><tr><th id=\"t1\" class=\"standard\">"
578                             + LocaleSupport.getLocalizedMessage(pageContext,
579                                     "org.dspace.app.webui.jsptag.ItemTag.file")
580                             + "</th>");
581
582                 if (multiFile)
583                 {
584
585                     out
586                         .println("<th id=\"t2\" class=\"standard\">"
587                                 + LocaleSupport
588                                         .getLocalizedMessage(pageContext,
589                                                 "org.dspace.app.webui.jsptag.ItemTag.description")
590                                 + "</th>");
591                 }
592
593                 out.println("<th id=\"t3\" class=\"standard\">"
594                     + LocaleSupport.getLocalizedMessage(pageContext,
595                             "org.dspace.app.webui.jsptag.ItemTag.filesize")
596                     + "</th><th id=\"t4\" class=\"standard\">"
597                     + LocaleSupport.getLocalizedMessage(pageContext,
598                             "org.dspace.app.webui.jsptag.ItemTag.fileformat")
599                     + "</th></tr>");
600
601                 // if primary bitstream is html, display a link for only that one to
602
// HTMLServlet
603
if (html)
604                 {
605                     // If no real Handle yet (e.g. because Item is in workflow)
606
// we use the 'fake' Handle db-id/1234 where 1234 is the
607
// database ID of the item.
608
if (handle == null)
609                     {
610                         handle = "db-id/" + item.getID();
611                     }
612
613                     out.print("<tr><td headers=\"t1\" class=\"standard\">");
614                     out.print(primaryBitstream.getName());
615
616                     if (multiFile)
617                     {
618                         out.print("</td><td headers=\"t2\" class=\"standard\">");
619
620                         String JavaDoc desc = primaryBitstream.getDescription();
621                         out.print((desc != null) ? desc : "");
622                     }
623
624                     out.print("</td><td headers=\"t3\" class=\"standard\">");
625                     out.print(primaryBitstream.getSize() / 1024);
626                     out.print("Kb</td><td headers=\"t4\" class=\"standard\">");
627                     out.print(primaryBitstream.getFormatDescription());
628                     out
629                         .print("</td><td class=\"standard\"><a target=\"_blank\" HREF=\"");
630                     out.print(request.getContextPath());
631                     out.print("/html/");
632                     out.print(handle + "/");
633                     out
634                         .print(UIUtil.encodeBitstreamName(primaryBitstream
635                                 .getName(), Constants.DEFAULT_ENCODING));
636                     out.print("\">"
637                         + LocaleSupport.getLocalizedMessage(pageContext,
638                                 "org.dspace.app.webui.jsptag.ItemTag.view")
639                         + "</a></td></tr>");
640                 }
641                 else
642                 {
643                     for (int i = 0; i < bundles.length; i++)
644                     {
645                         Bitstream[] bitstreams = bundles[i].getBitstreams();
646
647                         for (int k = 0; k < bitstreams.length; k++)
648                         {
649                             // Skip internal types
650
if (!bitstreams[k].getFormat().isInternal())
651                             {
652                                 out
653                                     .print("<tr><td headers=\"t1\" class=\"standard\">");
654                                 out.print(bitstreams[k].getName());
655
656                                 if (multiFile)
657                                 {
658                                     out
659                                         .print("</td><td headers=\"t2\" class=\"standard\">");
660
661                                     String JavaDoc desc = bitstreams[k].getDescription();
662                                     out.print((desc != null) ? desc : "");
663                                 }
664
665                                 out
666                                     .print("</td><td headers=\"t3\" class=\"standard\">");
667                                 out.print(bitstreams[k].getSize() / 1024);
668                                 out
669                                     .print("Kb</td><td headers=\"t4\" class=\"standard\">");
670                                 out.print(bitstreams[k].getFormatDescription());
671                                 out
672                                     .print("</td><td class=\"standard\" align=\"center\">");
673
674                                 // Work out what the bitstream link should be
675
// (persistent
676
// ID if item has Handle)
677
String JavaDoc bsLink = "<a target=\"_blank\" HREF=\""
678                                         + request.getContextPath();
679
680                                 if ((handle != null)
681                                         && (bitstreams[k].getSequenceID() > 0))
682                                 {
683                                     bsLink = bsLink + "/bitstream/"
684                                             + item.getHandle() + "/"
685                                             + bitstreams[k].getSequenceID() + "/";
686                                 }
687                                 else
688                                 {
689                                     bsLink = bsLink + "/retrieve/"
690                                             + bitstreams[k].getID() + "/";
691                                 }
692
693                                 bsLink = bsLink
694                                         + UIUtil.encodeBitstreamName(bitstreams[k]
695                                             .getName(),
696                                             Constants.DEFAULT_ENCODING) + "\">";
697
698                                 // is there a thumbnail bundle?
699
if ((thumbs.length > 0) && showThumbs)
700                                 {
701                                     String JavaDoc tName = bitstreams[k].getName() + ".jpg";
702                                   String JavaDoc tAltText = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.ItemTag.thumbnail");
703                                     Bitstream tb = thumbs[0]
704                                         . getBitstreamByName(tName);
705
706                                     if (tb != null)
707                                     {
708                                         String JavaDoc myPath = request.getContextPath()
709                                                 + "/retrieve/"
710                                                 + tb.getID()
711                                                 + "/"
712                                                 + UIUtil.encodeBitstreamName(tb
713                                                         .getName(),
714                                                         Constants.DEFAULT_ENCODING);
715
716                                         out.print(bsLink);
717                                         out.print("<img SRC=\"" + myPath + "\" ");
718                                         out.print("alt=\"" + tAltText
719                                                 + "\" /></a><br />");
720                                     }
721                                 }
722
723                                 out
724                                     .print(bsLink
725                                             + LocaleSupport
726                                                     .getLocalizedMessage(
727                                                             pageContext,
728                                                             "org.dspace.app.webui.jsptag.ItemTag.view")
729                                             + "</a></td></tr>");
730                             }
731                         }
732                     }
733                 }
734
735                 out.println("</table>");
736             }
737         }
738         catch(SQLException JavaDoc sqle)
739         {
740             throw new IOException JavaDoc(sqle.getMessage());
741         }
742
743         out.println("</td></tr></table>");
744     }
745
746     private void getThumbSettings()
747     {
748         showThumbs = ConfigurationManager
749                 .getBooleanProperty("webui.item.thumbnail.show");
750     }
751
752     /**
753      * Link to the item licence
754      */

755     private void showLicence() throws IOException JavaDoc
756     {
757         JspWriter JavaDoc out = pageContext.getOut();
758         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext
759                 .getRequest();
760
761         Bundle[] bundles = null;
762         try
763         {
764             bundles = item.getBundles("LICENSE");
765         }
766         catch(SQLException JavaDoc sqle)
767         {
768             throw new IOException JavaDoc(sqle.getMessage());
769         }
770
771         out.println("<table align=\"center\" class=\"attentionTable\"><tr>");
772
773         out.println("<td class=\"attentionCell\"><p><strong>"
774                 + LocaleSupport.getLocalizedMessage(pageContext,
775                         "org.dspace.app.webui.jsptag.ItemTag.itemprotected")
776                 + "</strong></p>");
777
778         for (int i = 0; i < bundles.length; i++)
779         {
780             Bitstream[] bitstreams = bundles[i].getBitstreams();
781
782             for (int k = 0; k < bitstreams.length; k++)
783             {
784                 out.print("<div align=\"center\" class=\"standard\">");
785                 out.print("<strong><a target=\"_blank\" HREF=\"");
786                 out.print(request.getContextPath());
787                 out.print("/retrieve/");
788                 out.print(bitstreams[k].getID() + "/");
789                 out.print(UIUtil.encodeBitstreamName(bitstreams[k].getName(),
790                         Constants.DEFAULT_ENCODING));
791                 out
792                         .print("\">"
793                                 + LocaleSupport
794                                         .getLocalizedMessage(pageContext,
795                                                 "org.dspace.app.webui.jsptag.ItemTag.viewlicence")
796                                 + "</a></strong></div>");
797             }
798         }
799
800         out.println("</td></tr></table>");
801     }
802
803     /**
804      * Find the style to use for a particular collection from dspace.cfg
805      */

806     private void getStyleFor(Collection c)
807     {
808         if (collectionStyles == null)
809         {
810             readCollectionStyleConfig();
811         }
812
813         String JavaDoc collStyle = (String JavaDoc) collectionStyles.get(c.getHandle());
814
815         if (collStyle == null)
816         {
817             // No specific style specified for this collection
818
style = "default";
819             return;
820         }
821
822         // Specific style specified. Check style exists
823
if (ConfigurationManager.getProperty("webui.itemdisplay." + collStyle) == null)
824         {
825             log
826                     .warn("dspace.cfg specifies undefined item metadata display style '"
827                             + collStyle
828                             + "' for collection "
829                             + c.getHandle()
830                             + ". Using default");
831             style = "default";
832             return;
833         }
834
835         // Style specified & exists
836
style = collStyle;
837     }
838
839     private static void readCollectionStyleConfig()
840     {
841         collectionStyles = new HashMap JavaDoc();
842
843         Enumeration JavaDoc e = ConfigurationManager.propertyNames();
844
845         while (e.hasMoreElements())
846         {
847             String JavaDoc key = (String JavaDoc) e.nextElement();
848
849             if (key.startsWith("webui.itemdisplay.")
850                     && key.endsWith(".collections"))
851             {
852                 String JavaDoc styleName = key.substring("webui.itemdisplay.".length(),
853                         key.length() - ".collections".length());
854
855                 String JavaDoc[] collections = ConfigurationManager.getProperty(key)
856                         .split(",");
857
858                 for (int i = 0; i < collections.length; i++)
859                 {
860                     collectionStyles.put(collections[i].trim(), styleName
861                             .toLowerCase());
862                 }
863
864             }
865         }
866     }
867 }
868
Popular Tags