1 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 ; 57 58 import java.sql.SQLException ; 59 import java.util.Enumeration ; 60 import java.util.HashMap ; 61 import java.util.Map ; 62 import java.util.StringTokenizer ; 63 64 import javax.servlet.http.HttpServletRequest ; 65 import javax.servlet.jsp.JspException ; 66 import javax.servlet.jsp.JspWriter ; 67 import javax.servlet.jsp.jstl.fmt.LocaleSupport; 68 import javax.servlet.jsp.tagext.TagSupport ; 69 70 137 public class ItemTag extends TagSupport 138 { 139 140 private Item item; 141 142 143 private Collection[] collections; 144 145 146 private String style; 147 148 149 private boolean showThumbs; 150 151 152 private static Map collectionStyles; 153 154 155 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"; 156 157 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 168 { 169 try 170 { 171 if (style == null || style.equals("")) 172 { 173 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 sqle) 196 { 197 throw new JspException (sqle); 198 } 199 catch (IOException ie) 200 { 201 throw new JspException (ie); 202 } 203 204 return SKIP_BODY; 205 } 206 207 212 public Item getItem() 213 { 214 return item; 215 } 216 217 223 public void setItem(Item itemIn) 224 { 225 item = itemIn; 226 } 227 228 233 public Collection[] getCollections() 234 { 235 return collections; 236 } 237 238 244 public void setCollections(Collection[] collectionsIn) 245 { 246 collections = collectionsIn; 247 } 248 249 254 public String getStyle() 255 { 256 return style; 257 } 258 259 265 public void setStyle(String styleIn) 266 { 267 style = styleIn; 268 } 269 270 public void release() 271 { 272 style = "default"; 273 item = null; 274 collections = null; 275 } 276 277 280 private void render() throws IOException 281 { 282 JspWriter out = pageContext.getOut(); 283 284 String 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 299 StringTokenizer st = new StringTokenizer (configLine, ","); 300 301 while (st.hasMoreTokens()) 302 { 303 String field = st.nextToken().trim(); 304 boolean isDate = false; 305 boolean isLink = false; 306 307 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 322 String [] eq = field.split("\\."); 323 String schema = eq[0]; 324 String element = eq[1]; 325 String 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 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(": </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 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 393 private void renderFull() throws IOException 394 { 395 JspWriter out = pageContext.getOut(); 396 397 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 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 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 477 private void listCollections() throws IOException 478 { 479 JspWriter out = pageContext.getOut(); 480 HttpServletRequest request = (HttpServletRequest ) pageContext 481 .getRequest(); 482 483 if (collections != null) 484 { 485 out.print("<tr><td class=\"metadataFieldLabel\">"); 486 if (item.getHandle()==null) { 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 516 private void listBitstreams() throws IOException 517 { 518 JspWriter out = pageContext.getOut(); 519 HttpServletRequest request = (HttpServletRequest ) 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 handle = item.getHandle(); 543 Bitstream primaryBitstream = null; 544 545 Bundle[] bunds = item.getBundles("ORIGINAL"); 546 Bundle[] thumbs = item.getBundles("THUMBNAIL"); 547 548 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 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 (html) 604 { 605 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 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 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 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 String 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 if ((thumbs.length > 0) && showThumbs) 700 { 701 String tName = bitstreams[k].getName() + ".jpg"; 702 String 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 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 sqle) 739 { 740 throw new IOException (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 755 private void showLicence() throws IOException 756 { 757 JspWriter out = pageContext.getOut(); 758 HttpServletRequest request = (HttpServletRequest ) pageContext 759 .getRequest(); 760 761 Bundle[] bundles = null; 762 try 763 { 764 bundles = item.getBundles("LICENSE"); 765 } 766 catch(SQLException sqle) 767 { 768 throw new IOException (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 806 private void getStyleFor(Collection c) 807 { 808 if (collectionStyles == null) 809 { 810 readCollectionStyleConfig(); 811 } 812 813 String collStyle = (String ) collectionStyles.get(c.getHandle()); 814 815 if (collStyle == null) 816 { 817 style = "default"; 819 return; 820 } 821 822 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 = collStyle; 837 } 838 839 private static void readCollectionStyleConfig() 840 { 841 collectionStyles = new HashMap (); 842 843 Enumeration e = ConfigurationManager.propertyNames(); 844 845 while (e.hasMoreElements()) 846 { 847 String key = (String ) e.nextElement(); 848 849 if (key.startsWith("webui.itemdisplay.") 850 && key.endsWith(".collections")) 851 { 852 String styleName = key.substring("webui.itemdisplay.".length(), 853 key.length() - ".collections".length()); 854 855 String [] 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 |