1 /* 2 * This file is part of *** M y C o R e *** 3 * See http://www.mycore.de/ for details. 4 * 5 * MyCoRe is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * MyCoRe is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 package org.mycore.frontend.basket; 20 21 import org.jdom2.Element; 22 import org.mycore.common.xml.MCRURIResolver; 23 24 /** 25 * Represents an entry in a basket. Each entry has at least 26 * a unique ID, for example the MCRObjectID, and an URI that 27 * can be used to read the object's XML representation to 28 * render the object in the basket UI. Each basket entry 29 * may have an optional comment. The basket entry provides 30 * methods to resolve the object's XML and to set in in the 31 * basket entry. This can be used by applications that wish 32 * to edit XML in the basket itself. 33 * 34 * @author Frank L\u00FCtzenkirchen 35 */ 36 public class MCRBasketEntry { 37 38 /** The ID of the object contained in this basket entry */ 39 private String id; 40 41 /** The URI where to read the object's XML data from */ 42 private String uri; 43 44 /** Optional comment for this basket entry */ 45 private String comment; 46 47 /** The XML data of the object in the basket, read from the URI */ 48 private Element content; 49 50 /** 51 * Creates a new basket entry. The XML that represents the object 52 * is not immediately read from the given URI. Call resolveContent() to 53 * read the content. 54 * 55 * @param id the ID of the object to add to the basket. 56 * @param uri the URI where to read the object's xml data from 57 */ 58 public MCRBasketEntry(String id, String uri) { 59 this.id = id; 60 this.uri = uri; 61 } 62 63 /** Returns the ID of the object contained in this basket entry */ 64 public String getID() { 65 return id; 66 } 67 68 /** Returns the URI where to read the object's XML data from */ 69 public String getURI() { 70 return uri; 71 } 72 73 /** 74 * Reads the XML data of the object in the basket entry, using the given URI, 75 * and stores it in the basket entry. 76 */ 77 public void resolveContent() { 78 if ((uri != null) && !uri.isEmpty()) { 79 setContent(MCRURIResolver.instance().resolve(uri)); 80 } 81 } 82 83 /** 84 * Returns the XML data of the object in the basket entry, or null if 85 * setContent() or resolveContent() was not called yet. 86 */ 87 public Element getContent() { 88 return content; 89 } 90 91 /** 92 * Sets the XML data of the object in the basket entry. 93 */ 94 public void setContent(Element content) { 95 this.content = content.clone(); 96 } 97 98 /** 99 * Returns the optional comment set for this basket entry. 100 */ 101 public String getComment() { 102 return comment; 103 } 104 105 /** 106 * Sets the optional comment for this basket entry. 107 */ 108 public void setComment(String comment) { 109 this.comment = comment; 110 } 111 112 @Override 113 public boolean equals(Object obj) { 114 if (obj instanceof MCRBasketEntry) { 115 return ((MCRBasketEntry) obj).id.equals(id); 116 } else { 117 return false; 118 } 119 } 120 121 @Override 122 public int hashCode() { 123 return id.hashCode(); 124 } 125 }