Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2004, 2005 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.ui.internal.intro.impl.html;
 
 import java.util.Map;
 import java.util.Set;

Convenience class for generating HTML elements.
 
 public final class HTMLUtil {
    
Creates an HTML opening element of the form <elementName elementAttributes>

Parameters:
elementName the name of the element to create
elementAttributes a map of attribute names and values to be inserted into the element start tag
insertLineBreak true to insert a line break after the start tag is closed, false otherwise
Returns:
 
     public static StringBuffer createHTMLStartTag(String elementName,
             Map elementAttributesboolean insertLineBreak) {
         StringBuffer element = new StringBuffer();
         if (elementName != null) {
             // open the start tag
             element.append(openHTMLStartTag(elementName));
             // add the attributes, if there are any
             if (elementAttributes != null && !(elementAttributes.isEmpty()))
                 element.append(.).append(
                         createAttributeList(elementAttributes));
             // close the start tag
             element.append(closeHTMLTag(insertLineBreak));
         }
         return element;
     }

    
Creates an HTML start tag of the form <elementName>

Parameters:
elementName the name of the element to create
insertLineBreak true to insert a new line after the start tag
Returns:
 
     public static StringBuffer createHTMLStartTag(String elementName,
             boolean insertLineBreak) {
         return createHTMLStartTag(elementNamenullinsertLineBreak);
     }

    
Creates an HTML start tag of the form <elementName>and inserts a line break after the start tag

Parameters:
elementName the name of the element to create
Returns:
 
     public static StringBuffer createHTMLStartTag(String elementName) {
         return createHTMLStartTag(elementNamenulltrue);
     }

    
Creates an HTML closing element of the form </elementName>

Parameters:
elementName the name of the closing element to create
addNewLine true to add a new line at the end
Returns:
 
     public static StringBuffer createHTMLEndTag(String elementName,
             boolean addNewLine) {
         StringBuffer closingElement = new StringBuffer();
         if (elementName != null)
             closingElement.append(.).append(
                     .).append(elementName)
                     .append(closeHTMLTag(addNewLine));
         return closingElement;
     }

    
Given a map of attribute names and values, this method will create a StringBuffer of the attributes in the form: attrName="attrValue". These attributes can appear in the start tag of an HTML element.

Parameters:
attributes the attributes to be converted into a String list
Returns:
    public static String createAttributeList(Map attributes) {
        if (attributes == null)
            return null;
        StringBuffer attributeList = new StringBuffer();
        Set attrNames = attributes.keySet();
        for (Iterator it = attrNames.iterator(); it.hasNext();) {
            Object name = it.next();
            Object value = attributes.get(name);
            if ((name instanceof String) && (value instanceof String)) {
                attributeList.append(createAttribute((Stringname,
                        (Stringvalue));
                if (it.hasNext()) {
                    attributeList.append(.);
                }
            }
        }
        return attributeList.toString();
    }

    
Creates an HTML attribute of the form attrName="attrValue"

Parameters:
attrName the name of the attribute
attrValue the value of the attribute
Returns:
    public static StringBuffer createAttribute(String attrNameString attrValue) {
        StringBuffer attribute = new StringBuffer();
        if (attrName != null && attrValue != null) {
            attribute.append(attrName).append(.)
                    .append(.).append(attrValue)
                    .append(.);
        }
        return attribute;
    }
    public static StringBuffer openHTMLStartTag(String elementName) {
        return new StringBuffer().append(.).append(
                elementName);
    }
    public static StringBuffer closeHTMLTag() {
        return closeHTMLTag(true);
    }
    public static StringBuffer closeHTMLTag(boolean newLine) {
        StringBuffer closing = new StringBuffer()
                .append(.);
        if (newLine)
            closing.append(.);
        return closing;
    }

    
Determine if the contents of two character arrays are equal

Parameters:
a
b
Returns:
    public static boolean equalCharArrayContent(char[] achar[] b) {
        if (a.length != b.length)
            return false;
        for (int i = 0; i < a.lengthi++) {
            if (a[i] != b[i])
                return false;
        }
        return true;
    }
New to GrepCode? Check out our FAQ X