1 10 11 package org.mmbase.applications.media.urlcomposers; 12 13 import org.mmbase.applications.media.builders.MediaProviders; 14 import org.mmbase.applications.media.builders.MediaSources; 15 import org.mmbase.module.core.MMObjectNode; 16 import org.mmbase.util.HashCodeUtil; 17 import org.mmbase.applications.media.Format; 18 19 import java.util.*; 20 21 35 public class URLComposer { 36 protected MMObjectNode source; 37 protected MMObjectNode provider; 38 protected Map info; 39 40 public void init(MMObjectNode provider, MMObjectNode source, MMObjectNode fragment, Map info, Set cacheExpireObjects) { 41 if(cacheExpireObjects!=null) { 42 cacheExpireObjects.add(provider); 43 cacheExpireObjects.add(source); 44 45 } 46 47 if (source == null) throw new RuntimeException ("Source may not be null in a URLComposer object"); 48 if (provider == null) throw new RuntimeException ("Provider may not be null in a URLComposer object"); 49 this.provider = provider; 50 this.source = source; 51 this.info = info; 52 if (this.info == null) this.info = new java.util.Hashtable (); 53 } 54 55 public MMObjectNode getSource() { return source; } 56 public MMObjectNode getProvider() { return provider;} 57 public Map getInfo() { return info; } 58 59 63 public Format getFormat() { 64 return Format.get(source.getIntValue("format")); 65 } 66 67 71 public String getMimeType() { 72 return getFormat().getMimeType(); 73 } 74 75 76 77 public String getGUIIndicator(Map options) { 78 Locale locale = (Locale) options.get("locale"); 79 return getFormat().getGUIIndicator(locale); 80 } 81 82 public String getDescription(Map options) { 83 return null; } 85 86 91 public boolean canCompose() { 92 return true; 93 } 94 95 99 protected StringBuffer getURLBuffer() { 100 StringBuffer buff = new StringBuffer (provider.getStringValue("protocol") + "://" + provider.getStringValue("host") + provider.getStringValue("rootpath") + source.getStringValue("url")); 101 return buff; 102 } 103 107 108 public final String getURL() { 109 return getURLBuffer().toString(); 110 } 111 112 public boolean isAvailable() { 113 boolean sourceAvailable = (source != null && source.getIntValue("state") == MediaSources.STATE_DONE); 114 boolean providerAvailable = (provider.getIntValue("state") == MediaProviders.STATE_ON); 115 return providerAvailable && sourceAvailable; 116 } 117 118 public String toString() { 119 String className = getClass().getName().substring(getClass().getName().lastIndexOf(".") + 1); 121 if (isAvailable()) { 122 return className + "/" + getFormat() + ": " + getURL(); 123 } else { 124 return "{" + className + "/" + getFormat() + ": " + getURL() + "}"; 125 } 126 } 127 128 131 public boolean equals(Object o) { 132 if (o == this) return true; 133 if (o == null) return false; 134 if (o.getClass().equals(getClass())) { 135 URLComposer r = (URLComposer) o; 136 return 137 (source == null ? r.source == null : source.getNumber() == r.source.getNumber()) && 138 (provider == null ? r.provider == null : provider.getNumber() == r.provider.getNumber()) && 139 (info == null ? r.info == null : info.equals(r.info)); 140 } 141 return false; 142 } 143 144 145 148 public int hashCode() { 149 int result = 0; 150 result = HashCodeUtil.hashCode(result, source == null ? 0 : source.getNumber()); 151 result = HashCodeUtil.hashCode(result, provider == null ? 0 : provider.getNumber()); 152 result = HashCodeUtil.hashCode(result, info == null ? 0 : info.hashCode()); 153 return result; 154 } 155 } 156 | Popular Tags |