1 11 package org.eclipse.ui.internal.intro.impl.html; 12 13 import java.util.Iterator ; 14 import java.util.Map ; 15 import java.util.Set ; 16 17 20 public final class HTMLUtil { 21 35 public static StringBuffer createHTMLStartTag(String elementName, 36 Map elementAttributes, boolean insertLineBreak) { 37 StringBuffer element = new StringBuffer (); 38 if (elementName != null) { 39 element.append(openHTMLStartTag(elementName)); 41 if (elementAttributes != null && !(elementAttributes.isEmpty())) 43 element.append(IIntroHTMLConstants.SPACE).append( 44 createAttributeList(elementAttributes)); 45 element.append(closeHTMLTag(insertLineBreak)); 47 } 48 return element; 49 } 50 51 60 public static StringBuffer createHTMLStartTag(String elementName, 61 boolean insertLineBreak) { 62 return createHTMLStartTag(elementName, null, insertLineBreak); 63 } 64 65 73 public static StringBuffer createHTMLStartTag(String elementName) { 74 return createHTMLStartTag(elementName, null, true); 75 } 76 77 86 public static StringBuffer createHTMLEndTag(String elementName, 87 boolean addNewLine) { 88 StringBuffer closingElement = new StringBuffer (); 89 if (elementName != null) 90 closingElement.append(IIntroHTMLConstants.LT).append( 91 IIntroHTMLConstants.FORWARD_SLASH).append(elementName) 92 .append(closeHTMLTag(addNewLine)); 93 return closingElement; 94 } 95 96 105 public static String createAttributeList(Map attributes) { 106 if (attributes == null) 107 return null; 108 StringBuffer attributeList = new StringBuffer (); 109 Set attrNames = attributes.keySet(); 110 for (Iterator it = attrNames.iterator(); it.hasNext();) { 111 Object name = it.next(); 112 Object value = attributes.get(name); 113 if ((name instanceof String ) && (value instanceof String )) { 114 attributeList.append(createAttribute((String ) name, 115 (String ) value)); 116 if (it.hasNext()) { 117 attributeList.append(IIntroHTMLConstants.SPACE); 118 } 119 } 120 } 121 return attributeList.toString(); 122 } 123 124 133 public static StringBuffer createAttribute(String attrName, String attrValue) { 134 StringBuffer attribute = new StringBuffer (); 135 if (attrName != null && attrValue != null) { 136 attribute.append(attrName).append(IIntroHTMLConstants.EQUALS) 137 .append(IIntroHTMLConstants.QUOTE).append(attrValue) 138 .append(IIntroHTMLConstants.QUOTE); 139 } 140 return attribute; 141 } 142 143 public static StringBuffer openHTMLStartTag(String elementName) { 144 return new StringBuffer ().append(IIntroHTMLConstants.LT).append( 145 elementName); 146 } 147 148 public static StringBuffer closeHTMLTag() { 149 return closeHTMLTag(true); 150 } 151 152 public static StringBuffer closeHTMLTag(boolean newLine) { 153 StringBuffer closing = new StringBuffer () 154 .append(IIntroHTMLConstants.GT); 155 if (newLine) 156 closing.append(IIntroHTMLConstants.NEW_LINE); 157 return closing; 158 } 159 160 167 public static boolean equalCharArrayContent(char[] a, char[] b) { 168 if (a.length != b.length) 169 return false; 170 for (int i = 0; i < a.length; i++) { 171 if (a[i] != b[i]) 172 return false; 173 } 174 return true; 175 } 176 } 177 | Popular Tags |