1 package org.jahia.taglibs.util; 2 3 import java.util.Enumeration ; 4 5 import javax.servlet.http.HttpServletRequest ; 6 7 import org.jahia.exceptions.JahiaException; 8 import org.jahia.gui.GuiBean; 9 import org.jahia.utils.JahiaConsole; 10 11 17 public class Utils { 18 19 private static String SEPARATOR = "_"; 20 21 22 31 public static String buildUniqueName (String parentName, String tagName) { 32 33 StringBuffer buffer = new StringBuffer (parentName); 34 buffer.append(SEPARATOR); 35 buffer.append(tagName); 36 return buffer.toString(); 37 } 38 39 40 49 public static String getParentName (String completeName, String tagName) { 50 51 if (completeName.endsWith(SEPARATOR + tagName)) { 52 int last = completeName.length() - tagName.length() - 1; return completeName.substring(0, last); 55 56 } else if (completeName.equals(tagName)) { 57 return ""; 59 } 60 return completeName; 62 } 63 64 65 73 public static String replace(String str, String token, 74 String replaceValue) { 75 76 String result = ""; 77 int i = str.indexOf(token); 78 while (i != -1) { 79 result += str.substring(0,i) + replaceValue; 80 str = str.substring(i + token.length(), str.length()); 81 i = str.indexOf(token); 82 } 83 return result + str; 84 } 85 86 87 99 public static String insertContextPath(String contextPath, String link) { 100 101 int pos = link.indexOf("src="); 102 if (pos != -1) { 103 StringBuffer tmp = new StringBuffer (link); 104 tmp = tmp.insert(pos + 5, contextPath + "/"); 106 return tmp.toString(); 107 } 108 return link; 110 } 111 112 113 123 public static String getShortClassName(Class theClass) { 124 125 String fullName = theClass.getName(); 126 int lastDot = fullName.lastIndexOf("."); 127 if (lastDot == -1) { 128 JahiaConsole.println("Utils: getShortClassName ", "The class name contains no dot."); 129 return fullName; 130 } 131 return fullName.substring(lastDot + 1); 132 } 133 134 140 public static int enumSize(Enumeration enumeration) { 141 int i = 0; 142 while(enumeration.hasMoreElements()) { 143 i++; 144 enumeration.nextElement(); 145 } 146 return i; 147 } 148 149 150 156 public static boolean isBrowserVersion(HttpServletRequest req, GuiBean gui, String version) 157 throws JahiaException { 158 159 version = version.toUpperCase(); 160 if (version.equals("NS")) { 161 return gui.isNS(req); 162 } 163 if (version.equals("NS4")) { 164 return gui.isNS4(req); 165 } 166 if (version.equals("NS6")) { 167 return gui.isNS6(req); 168 } 169 if (version.equals("IE")) { 170 return gui.isIE(req); 171 } 172 if (version.equals("IE4")) { 173 return gui.isIE4(req); 174 } 175 if (version.equals("IE5")) { 176 return gui.isIE5(req); 177 } 178 if (version.equals("IE6")) { 179 return gui.isIE6(req); 180 } 181 return false; 182 } 183 184 } 185 | Popular Tags |