-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
ItemTag.java
1156 lines (1020 loc) · 40.8 KB
/
ItemTag.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.webui.jsptag;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.jstl.fmt.LocaleSupport;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Logger;
import org.dspace.app.util.DCInputsReaderException;
import org.dspace.app.util.MetadataExposure;
import org.dspace.app.util.Util;
import org.dspace.app.webui.util.StyleSelection;
import org.dspace.app.webui.util.UIUtil;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.browse.BrowseException;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Collection;
import org.dspace.content.DCDate;
import org.dspace.content.Metadatum;
import org.dspace.content.Item;
import org.dspace.content.authority.MetadataAuthorityManager;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.I18nUtil;
import org.dspace.core.PluginManager;
import org.dspace.core.Utils;
/**
* <P>
* JSP tag for displaying an item.
* </P>
* <P>
* The fields that are displayed can be configured in <code>dspace.cfg</code>
* using the <code>webui.itemdisplay.(style)</code> property. The form is
* </P>
*
* <PRE>
*
* <schema prefix>.<element>[.<qualifier>|.*][(date)|(link)], ...
*
* </PRE>
*
* <P>
* For example:
* </P>
*
* <PRE>
*
* dc.title = Dublin Core element 'title' (unqualified)
* dc.title.alternative = DC element 'title', qualifier 'alternative'
* dc.title.* = All fields with Dublin Core element 'title' (any or no qualifier)
* dc.identifier.uri(link) = DC identifier.uri, render as a link
* dc.date.issued(date) = DC date.issued, render as a date
* dc.identifier.doi(doi) = DC identifier.doi, render as link to http://dx.doi.org
* dc.identifier.hdl(handle) = DC identifier.hanlde, render as link to http://hdl.handle.net
* dc.relation.isPartOf(resolver) = DC relation.isPartOf, render as link to the base url of the resolver
* according to the specified urn in the metadata value (doi:xxxx, hdl:xxxxx,
* urn:issn:xxxx, etc.)
*
* </PRE>
*
* <P>
* When using "resolver" in webui.itemdisplay to render identifiers as resolvable
* links, the base URL is taken from <code>webui.resolver.<n>.baseurl</code>
* where <code>webui.resolver.<n>.urn</code> matches the urn specified in the metadata value.
* The value is appended to the "baseurl" as is, so the baseurl need to end with slash almost in any case.
* If no urn is specified in the value it will be displayed as simple text.
*
* <PRE>
*
* webui.resolver.1.urn = doi
* webui.resolver.1.baseurl = http://dx.doi.org/
* webui.resolver.2.urn = hdl
* webui.resolver.2.baseurl = http://hdl.handle.net/
*
* </PRE>
*
* For the doi and hdl urn defaults values are provided, respectively http://dx.doi.org/ and
* http://hdl.handle.net/ are used.<br>
*
* If a metadata value with style: "doi", "handle" or "resolver" matches a URL
* already, it is simply rendered as a link with no other manipulation.
* </P>
*
* <PRE>
*
* <P>
* If an item has no value for a particular field, it won't be displayed. The
* name of the field for display will be drawn from the current UI dictionary,
* using the key:
* </P>
*
* <PRE>
*
* "metadata.<style.>.<field>"
*
* e.g. "metadata.thesis.dc.title" "metadata.thesis.dc.contributor.*"
* "metadata.thesis.dc.date.issued"
*
*
* if this key is not found will be used the more general one
*
* "metadata.<field>"
*
* e.g. "metadata.dc.title" "metadata.dc.contributor.*"
* "metadata.dc.date.issued"
*
* </PRE>
*
* <P>
* You need to specify which strategy use for select the style for an item.
* </P>
*
* <PRE>
*
* plugin.single.org.dspace.app.webui.util.StyleSelection = \
* org.dspace.app.webui.util.CollectionStyleSelection
* #org.dspace.app.webui.util.MetadataStyleSelection
*
* </PRE>
*
* <P>
* With the Collection strategy you can also specify which collections use which
* views.
* </P>
*
* <PRE>
*
* webui.itemdisplay.<style>.collections = <collection handle>, ...
*
* </PRE>
*
* <P>
* FIXME: This should be more database-driven
* </P>
*
* <PRE>
*
* webui.itemdisplay.thesis.collections = 123456789/24, 123456789/35
*
* </PRE>
*
* <P>
* With the Metadata strategy you MUST specify which metadata use as name of the
* style.
* </P>
*
* <PRE>
*
* webui.itemdisplay.metadata-style = schema.element[.qualifier|.*]
*
* e.g. "dc.type"
*
* </PRE>
*
* @author Robert Tansley
* @version $Revision$
*/
public class ItemTag extends TagSupport
{
private static final String HANDLE_DEFAULT_BASEURL = "http://hdl.handle.net/";
private static final String DOI_DEFAULT_BASEURL = "http://dx.doi.org/";
/** Item to display */
private transient Item item;
/** Collections this item appears in */
private transient Collection[] collections;
/** The style to use - "default" or "full" */
private String style;
/** Whether to show preview thumbs on the item page */
private boolean showThumbs;
/** Default DC fields to display, in absence of configuration */
private static String 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";
/** log4j logger */
private static Logger log = Logger.getLogger(ItemTag.class);
private StyleSelection styleSelection = (StyleSelection) PluginManager.getSinglePlugin(StyleSelection.class);
/** Hashmap of linked metadata to browse, from dspace.cfg */
private static Map<String,String> linkedMetadata;
/** Hashmap of urn base url resolver, from dspace.cfg */
private static Map<String,String> urn2baseurl;
/** regex pattern to capture the style of a field, ie <code>schema.element.qualifier(style)</code> */
private Pattern fieldStylePatter = Pattern.compile(".*\\((.*)\\)");
private static final long serialVersionUID = -3841266490729417240L;
static {
int i;
linkedMetadata = new HashMap<String, String>();
String linkMetadata;
i = 1;
do {
linkMetadata = ConfigurationManager.getProperty("webui.browse.link."+i);
if (linkMetadata != null) {
String[] linkedMetadataSplit = linkMetadata.split(":");
String indexName = linkedMetadataSplit[0].trim();
String metadataName = linkedMetadataSplit[1].trim();
linkedMetadata.put(indexName, metadataName);
}
i++;
} while (linkMetadata != null);
urn2baseurl = new HashMap<String, String>();
String urn;
i = 1;
do {
urn = ConfigurationManager.getProperty("webui.resolver."+i+".urn");
if (urn != null) {
String baseurl = ConfigurationManager.getProperty("webui.resolver."+i+".baseurl");
if (baseurl != null){
urn2baseurl.put(urn, baseurl);
} else {
log.warn("Wrong webui.resolver configuration, you need to specify both webui.resolver.<n>.urn and webui.resolver.<n>.baseurl: missing baseurl for n = "+i);
}
}
i++;
} while (urn != null);
// Set sensible default if no config is found for doi & handle
if (!urn2baseurl.containsKey("doi")){
urn2baseurl.put("doi",DOI_DEFAULT_BASEURL);
}
if (!urn2baseurl.containsKey("hdl")){
urn2baseurl.put("hdl",HANDLE_DEFAULT_BASEURL);
}
}
public ItemTag()
{
super();
getThumbSettings();
}
public int doStartTag() throws JspException
{
try
{
if (style == null || style.equals(""))
{
style = styleSelection.getStyleForItem(item);
}
if (style.equals("full"))
{
renderFull();
}
else
{
render();
}
}
catch (SQLException sqle)
{
throw new JspException(sqle);
}
catch (IOException ie)
{
throw new JspException(ie);
}
catch (DCInputsReaderException ex)
{
throw new JspException(ex);
}
return SKIP_BODY;
}
/**
* Get the item this tag should display
*
* @return the item
*/
public Item getItem()
{
return item;
}
/**
* Set the item this tag should display
*
* @param itemIn
* the item to display
*/
public void setItem(Item itemIn)
{
item = itemIn;
}
/**
* Get the collections this item is in
*
* @return the collections
*/
public Collection[] getCollections()
{
return (Collection[]) ArrayUtils.clone(collections);
}
/**
* Set the collections this item is in
*
* @param collectionsIn
* the collections
*/
public void setCollections(Collection[] collectionsIn)
{
collections = (Collection[]) ArrayUtils.clone(collectionsIn);
}
/**
* Get the style this tag should display
*
* @return the style
*/
public String getStyle()
{
return style;
}
/**
* Set the style this tag should display
*
* @param styleIn
* the Style to display
*/
public void setStyle(String styleIn)
{
style = styleIn;
}
public void release()
{
style = "default";
item = null;
collections = null;
}
/**
* Render an item in the given style
*/
private void render() throws IOException, SQLException, DCInputsReaderException
{
JspWriter out = pageContext.getOut();
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
Context context = UIUtil.obtainContext(request);
Locale sessionLocale = UIUtil.getSessionLocale(request);
String configLine = styleSelection.getConfigurationForStyle(style);
if (configLine == null)
{
configLine = defaultFields;
}
out.println("<table class=\"table itemDisplayTable\">");
/*
* Break down the configuration into fields and display them
*
* FIXME?: it may be more efficient to do some processing once, perhaps
* to a more efficient intermediate class, but then it would become more
* difficult to reload the configuration "on the fly".
*/
StringTokenizer st = new StringTokenizer(configLine, ",");
while (st.hasMoreTokens())
{
String field = st.nextToken().trim();
boolean isDate = false;
boolean isLink = false;
boolean isResolver = false;
boolean isNoBreakLine = false;
boolean isDisplay = false;
String style = null;
Matcher fieldStyleMatcher = fieldStylePatter.matcher(field);
if (fieldStyleMatcher.matches()){
style = fieldStyleMatcher.group(1);
}
String browseIndex;
try
{
browseIndex = getBrowseField(field);
}
catch (BrowseException e)
{
log.error(e);
browseIndex = null;
}
// Find out if the field should rendered with a particular style
if (style != null)
{
isDate = style.contains("date");
isLink = style.contains("link");
isNoBreakLine = style.contains("nobreakline");
isDisplay = style.equals("inputform");
isResolver = style.contains("resolver") || urn2baseurl.keySet().contains(style);
field = field.replaceAll("\\("+style+"\\)", "");
}
// Get the separate schema + element + qualifier
String[] eq = field.split("\\.");
String schema = eq[0];
String element = eq[1];
String qualifier = null;
if (eq.length > 2 && eq[2].equals("*"))
{
qualifier = Item.ANY;
}
else if (eq.length > 2)
{
qualifier = eq[2];
}
// check for hidden field, even if it's configured..
if (MetadataExposure.isHidden(context, schema, element, qualifier))
{
continue;
}
// FIXME: Still need to fix for metadata language?
Metadatum[] values = item.getMetadata(schema, element, qualifier, Item.ANY);
if (values.length > 0)
{
out.print("<tr><td class=\"metadataFieldLabel\">");
String label = null;
try
{
label = I18nUtil.getMessage("metadata."
+ ("default".equals(this.style) ? "" : this.style + ".") + field,
context);
}
catch (MissingResourceException e)
{
// if there is not a specific translation for the style we
// use the default one
label = LocaleSupport.getLocalizedMessage(pageContext,
"metadata." + field);
}
out.print(label);
out.print(": </td><td class=\"metadataFieldValue\">");
//If the values are in controlled vocabulary and the display value should be shown
if (isDisplay){
List<String> displayValues = new ArrayList<String>();
displayValues = Util.getControlledVocabulariesDisplayValueLocalized(item, values, schema, element, qualifier, sessionLocale);
if (displayValues != null && !displayValues.isEmpty())
{
for (int d = 0; d < displayValues.size(); d++)
{
out.print(displayValues.get(d));
if (d<displayValues.size()-1) out.print(" <br/>");
}
}
out.print("</td>");
continue;
}
for (int j = 0; j < values.length; j++)
{
if (values[j] != null && values[j].value != null)
{
if (j > 0)
{
if (isNoBreakLine)
{
String separator = ConfigurationManager
.getProperty("webui.itemdisplay.nobreakline.separator");
if (separator == null)
{
separator = "; ";
}
out.print(separator);
}
else
{
out.print("<br />");
}
}
if (isLink)
{
out.print("<a href=\"" + values[j].value + "\">"
+ Utils.addEntities(values[j].value) + "</a>");
}
else if (isDate)
{
DCDate dd = new DCDate(values[j].value);
// Parse the date
out.print(UIUtil.displayDate(dd, false, false, (HttpServletRequest)pageContext.getRequest()));
}
else if (isResolver)
{
String value = values[j].value;
if (value.startsWith("http://")
|| value.startsWith("https://")
|| value.startsWith("ftp://")
|| value.startsWith("ftps://"))
{
// Already a URL, print as if it was a regular link
out.print("<a href=\"" + value + "\">"
+ Utils.addEntities(value) + "</a>");
}
else
{
String foundUrn = null;
if (!style.equals("resolver"))
{
foundUrn = style;
}
else
{
for (String checkUrn : urn2baseurl.keySet())
{
if (value.startsWith(checkUrn))
{
foundUrn = checkUrn;
}
}
}
if (foundUrn != null)
{
if (value.startsWith(foundUrn + ":"))
{
value = value.substring(foundUrn.length()+1);
}
String url = urn2baseurl.get(foundUrn);
out.print("<a href=\"" + url
+ value + "\">"
+ Utils.addEntities(values[j].value)
+ "</a>");
}
else
{
out.print(value);
}
}
}
else if (browseIndex != null)
{
String argument, value;
if ( values[j].authority != null &&
values[j].confidence >= MetadataAuthorityManager.getManager()
.getMinConfidence( values[j].schema, values[j].element, values[j].qualifier))
{
argument = "authority";
value = values[j].authority;
}
else
{
argument = "value";
value = values[j].value;
}
out.print("<a class=\"" + ("authority".equals(argument)?"authority ":"") + browseIndex + "\""
+ "href=\"" + request.getContextPath() + "/browse?type=" + browseIndex + "&" + argument + "="
+ URLEncoder.encode(value, "UTF-8") + "\">" + Utils.addEntities(values[j].value)
+ "</a>");
}
else
{
out.print(Utils.addEntities(values[j].value));
}
}
}
out.println("</td></tr>");
}
}
listCollections();
out.println("</table><br/>");
listBitstreams();
if (ConfigurationManager
.getBooleanProperty("webui.licence_bundle.show"))
{
out.println("<br/><br/>");
showLicence();
}
}
/**
* Render full item record
*/
private void renderFull() throws IOException, SQLException
{
JspWriter out = pageContext.getOut();
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
Context context = UIUtil.obtainContext(request);
// Get all the metadata
Metadatum[] values = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
out.println("<div class=\"panel panel-info\"><div class=\"panel-heading\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.full") + "</div>");
// Three column table - DC field, value, language
out.println("<table class=\"panel-body table itemDisplayTable\">");
out.println("<tr><th id=\"s1\" class=\"standard\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.dcfield")
+ "</th><th id=\"s2\" class=\"standard\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.value")
+ "</th><th id=\"s3\" class=\"standard\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.lang")
+ "</th></tr>");
for (int i = 0; i < values.length; i++)
{
if (!MetadataExposure.isHidden(context, values[i].schema, values[i].element, values[i].qualifier))
{
out.print("<tr><td headers=\"s1\" class=\"metadataFieldLabel\">");
out.print(values[i].schema);
out.print("." + values[i].element);
if (values[i].qualifier != null)
{
out.print("." + values[i].qualifier);
}
out.print("</td><td headers=\"s2\" class=\"metadataFieldValue\">");
out.print(Utils.addEntities(values[i].value));
out.print("</td><td headers=\"s3\" class=\"metadataFieldValue\">");
if (values[i].language == null)
{
out.print("-");
}
else
{
out.print(values[i].language);
}
out.println("</td></tr>");
}
}
listCollections();
out.println("</table></div><br/>");
listBitstreams();
if (ConfigurationManager
.getBooleanProperty("webui.licence_bundle.show"))
{
out.println("<br/><br/>");
showLicence();
}
}
/**
* List links to collections if information is available
*/
private void listCollections() throws IOException
{
JspWriter out = pageContext.getOut();
HttpServletRequest request = (HttpServletRequest) pageContext
.getRequest();
if (collections != null)
{
out.print("<tr><td class=\"metadataFieldLabel\">");
if (item.getHandle()==null) // assume workspace item
{
out.print(LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.submitted"));
}
else
{
out.print(LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.appears"));
}
out.print("</td><td class=\"metadataFieldValue\""+
(style.equals("full")?"colspan=\"2\"":"")
+">");
for (int i = 0; i < collections.length; i++)
{
out.print("<a href=\"");
out.print(request.getContextPath());
out.print("/handle/");
out.print(collections[i].getHandle());
out.print("\">");
out.print(collections[i].getMetadata("name"));
out.print("</a><br/>");
}
out.println("</td></tr>");
}
}
/**
* List bitstreams in the item
*/
private void listBitstreams() throws IOException
{
JspWriter out = pageContext.getOut();
HttpServletRequest request = (HttpServletRequest) pageContext
.getRequest();
out.print("<div class=\"panel panel-info\">");
out.println("<div class=\"panel-heading\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.files")
+ "</div>");
try
{
Bundle[] bundles = item.getBundles("ORIGINAL");
boolean filesExist = false;
for (Bundle bnd : bundles)
{
filesExist = bnd.getBitstreams().length > 0;
if (filesExist)
{
break;
}
}
// if user already has uploaded at least one file
if (!filesExist)
{
out.println("<div class=\"panel-body\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.files.no")
+ "</div>");
}
else
{
boolean html = false;
String handle = item.getHandle();
Bitstream primaryBitstream = null;
Bundle[] bunds = item.getBundles("ORIGINAL");
Bundle[] thumbs = item.getBundles("THUMBNAIL");
// if item contains multiple bitstreams, display bitstream
// description
boolean multiFile = false;
Bundle[] allBundles = item.getBundles();
for (int i = 0, filecount = 0; (i < allBundles.length)
&& !multiFile; i++)
{
filecount += allBundles[i].getBitstreams().length;
multiFile = (filecount > 1);
}
// check if primary bitstream is html
if (bunds[0] != null)
{
Bitstream[] bits = bunds[0].getBitstreams();
for (int i = 0; (i < bits.length) && !html; i++)
{
if (bits[i].getID() == bunds[0].getPrimaryBitstreamID())
{
html = bits[i].getFormat().getMIMEType().equals(
"text/html");
primaryBitstream = bits[i];
}
}
}
out
.println("<table class=\"table panel-body\"><tr><th id=\"t1\" class=\"standard\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.file")
+ "</th>");
if (multiFile)
{
out
.println("<th id=\"t2\" class=\"standard\">"
+ LocaleSupport
.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.description")
+ "</th>");
}
out.println("<th id=\"t3\" class=\"standard\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.filesize")
+ "</th><th id=\"t4\" class=\"standard\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.fileformat")
+ "</th><th> </th></tr>");
// if primary bitstream is html, display a link for only that one to
// HTMLServlet
if (html)
{
// If no real Handle yet (e.g. because Item is in workflow)
// we use the 'fake' Handle db-id/1234 where 1234 is the
// database ID of the item.
if (handle == null)
{
handle = "db-id/" + item.getID();
}
out.print("<tr><td headers=\"t1\" class=\"standard\">");
out.print("<a target=\"_blank\" href=\"");
out.print(request.getContextPath());
out.print("/html/");
out.print(handle + "/");
out
.print(UIUtil.encodeBitstreamName(primaryBitstream
.getName(), Constants.DEFAULT_ENCODING));
out.print("\">");
out.print(primaryBitstream.getName());
out.print("</a>");
if (multiFile)
{
out.print("</td><td headers=\"t2\" class=\"standard\">");
String desc = primaryBitstream.getDescription();
out.print((desc != null) ? desc : "");
}
out.print("</td><td headers=\"t3\" class=\"standard\">");
out.print(UIUtil.formatFileSize(primaryBitstream.getSize()));
out.print("</td><td headers=\"t4\" class=\"standard\">");
out.print(primaryBitstream.getFormatDescription());
out
.print("</td><td class=\"standard\"><a class=\"btn btn-primary\" target=\"_blank\" href=\"");
out.print(request.getContextPath());
out.print("/html/");
out.print(handle + "/");
out
.print(UIUtil.encodeBitstreamName(primaryBitstream
.getName(), Constants.DEFAULT_ENCODING));
out.print("\">"
+ LocaleSupport.getLocalizedMessage(pageContext,
"org.dspace.app.webui.jsptag.ItemTag.view")
+ "</a></td></tr>");
}
else
{
Context context = UIUtil
.obtainContext(request);
boolean showRequestCopy = false;
if ("all".equalsIgnoreCase(ConfigurationManager.getProperty("request.item.type")) ||
("logged".equalsIgnoreCase(ConfigurationManager.getProperty("request.item.type")) &&
context.getCurrentUser() != null))
{
showRequestCopy = true;
}
for (int i = 0; i < bundles.length; i++)
{
Bitstream[] bitstreams = bundles[i].getBitstreams();
for (int k = 0; k < bitstreams.length; k++)
{
// Skip internal types
if (!bitstreams[k].getFormat().isInternal())
{
// Work out what the bitstream link should be
// (persistent
// ID if item has Handle)
String bsLink = "target=\"_blank\" href=\""
+ request.getContextPath();
if ((handle != null)
&& (bitstreams[k].getSequenceID() > 0))
{
bsLink = bsLink + "/bitstream/"
+ item.getHandle() + "/"
+ bitstreams[k].getSequenceID() + "/";
}
else
{
bsLink = bsLink + "/retrieve/"
+ bitstreams[k].getID() + "/";
}
bsLink = bsLink
+ UIUtil.encodeBitstreamName(bitstreams[k]
.getName(),
Constants.DEFAULT_ENCODING) + "\">";
out
.print("<tr><td headers=\"t1\" class=\"standard\">");
out.print("<a ");
out.print(bsLink);
out.print(bitstreams[k].getName());
out.print("</a>");
if (multiFile)
{
out
.print("</td><td headers=\"t2\" class=\"standard\">");
String desc = bitstreams[k].getDescription();
out.print((desc != null) ? desc : "");
}
out
.print("</td><td headers=\"t3\" class=\"standard\">");
out.print(UIUtil.formatFileSize(bitstreams[k].getSize()));
out
.print("</td><td headers=\"t4\" class=\"standard\">");
out.print(bitstreams[k].getFormatDescription());
out
.print("</td><td class=\"standard\" align=\"center\">");
// is there a thumbnail bundle?
if ((thumbs.length > 0) && showThumbs)
{
String tName = bitstreams[k].getName() + ".jpg";
String tAltText = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.ItemTag.thumbnail");
Bitstream tb = thumbs[0]
. getBitstreamByName(tName);
if (tb != null)
{
if (AuthorizeManager.authorizeActionBoolean(context, tb, Constants.READ))
{
String myPath = request.getContextPath()
+ "/retrieve/"
+ tb.getID()
+ "/"
+ UIUtil.encodeBitstreamName(tb
.getName(),
Constants.DEFAULT_ENCODING);
out.print("<a ");
out.print(bsLink);
out.print("<img src=\"" + myPath + "\" ");
out.print("alt=\"" + tAltText
+ "\" /></a><br />");
}