1 10 11 package org.mmbase.applications.media.urlcomposers; 12 import org.mmbase.applications.media.builders.MediaFragments; 13 import org.mmbase.applications.media.Format; 14 import org.mmbase.module.core.MMObjectNode; 15 import java.util.*; 16 17 23 24 public class RealURLComposer extends FragmentURLComposer { 25 26 protected StringBuffer getURLBuffer() { 27 StringBuffer buff = super.getURLBuffer(); 28 if (getFormat().equals(Format.RM)) { 29 return getRMArgs(buff, fragment, info); 30 } else { 31 return buff; 32 } 33 } 34 35 public static StringBuffer getRMArgs(StringBuffer args, MMObjectNode fragment, Map info) { 36 if ("true".equals(info.get("nude"))) return args; 37 if (fragment != null) { long start = fragment.getLongValue("start"); 39 long end = fragment.getLongValue("stop"); 40 String sep = "?"; 41 if (start > -1 && start != end) { 42 appendTime(start, args.append(sep).append("start=")); 43 sep = "&"; 44 } 45 if (end > -1 && start != end) { 46 appendTime(end, args.append(sep).append("end=")); 47 sep = "&"; 48 } 49 String title = fragment.getStringValue("title").replaceAll(",",""); 51 args.append(sep).append("title=").append(makeRealCompatible(title)); 52 53 } 54 return args; 55 } 56 57 58 63 public static StringBuffer appendTime(long time, StringBuffer buf) { 64 time /= 10; 66 long centis = -1; 67 long s = 0; 68 long min = 0; 69 long h = 0; 70 long d = 0; 71 72 if (time != 0) { 73 centis = time % 100; 74 time /= 100; if (time != 0) { 76 s = time % 60; 77 time /= 60; if (time != 0) { 79 min = time % 60; 80 time /= 60; if (time != 0) { 82 h = time % 24; 83 d = time / 24; } 85 } 86 } 87 } 88 boolean append = false; 89 90 if (d > 0) append = true; 91 if (append) buf.append(d).append(':'); 92 append = true; 93 if (h > 0) append = true; 94 if (append) buf.append(h).append(':'); 95 if (min > 0) append = true; 96 if (append) buf.append(min).append(':'); 97 buf.append(s); 98 if (centis > 0) { 99 buf.append('.'); 100 if (centis < 10) buf.append('0'); 101 buf.append(centis); 102 } 103 104 return buf; 105 } 106 107 116 public static String makeRealCompatible(String s) { 117 if (s != null) { 118 char[] sArray = s.replace('#',' ').toCharArray(); 119 char[] dArray = new char[sArray.length]; 120 121 int j = 0; 122 for (int i=0;i<sArray.length;i++) { 123 if (Character.isLetterOrDigit(sArray[i]) ||(sArray[i]==' ')||(sArray[i]=='.')||(sArray[i]=='-')||(sArray[i]=='_')) { 124 dArray[j] = sArray[i]; 125 j++; 126 } 127 } 128 return (new String (dArray)).substring(0,j); 129 } 130 return ""; 131 132 } 133 134 135 } 136 | Popular Tags |