1 16 package org.apache.cocoon.portal.coplets.basket; 17 18 import java.io.Serializable ; 19 20 import org.apache.cocoon.portal.coplet.CopletInstanceData; 21 22 23 29 public class ContentItem extends AbstractItem implements Serializable { 30 31 32 protected String copletId; 33 34 protected boolean storesContent; 35 36 protected String url; 37 38 protected String stringRep; 39 40 protected byte[] content; 41 42 47 public ContentItem(CopletInstanceData cid, boolean content) { 48 this.copletId = cid.getId(); 49 this.storesContent = content; 50 } 51 52 57 public ContentItem(String url, boolean content) { 58 this.url = url; 59 this.storesContent = content; 60 } 61 62 65 public String getURL() { 66 return this.url; 67 } 68 69 72 public String getCopletId() { 73 return this.copletId; 74 } 75 76 79 public boolean isContent() { 80 return this.storesContent; 81 } 82 83 86 public void setContent(byte[] c) { 87 this.storesContent = true; 88 this.content = c; 89 } 90 91 94 public byte[] getContent() { 95 return this.content; 96 } 97 98 102 public int size() { 103 if ( this.content != null ) { 104 return this.content.length; 105 } 106 return -1; 107 } 108 109 112 public String toString() { 113 if ( this.stringRep == null ) { 114 if ( this.copletId != null ) { 115 this.stringRep = "Coplet:" + this.copletId + "(" + this.storesContent + ")"; 116 } else { 117 this.stringRep = "URL:" + this.url + "(" + this.storesContent + ")"; 118 } 119 } 120 return this.stringRep; 121 } 122 123 126 public boolean equalsItem(ContentItem ci) { 127 if ( ci != null && ci.storesContent == this.storesContent ) { 128 if ( ci.url != null && ci.url.equals(this.url)) { 129 return true; 130 } 131 if ( ci.copletId != null 132 && this.copletId != null 133 && ci.copletId.equals(this.copletId)) { 134 return true; 135 } 136 } 137 return false; 138 } 139 140 public void setTitle(String title) { 141 this.stringRep = title; 142 } 143 } 144 | Popular Tags |