Generates a HTML "link" string - Java java.lang

Java examples for java.lang:String HTML

Description

Generates a HTML "link" string

Demo Code


import org.apache.log4j.Logger;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.net.InetAddress;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class Main{
    /**//from  www.j  a v a2  s  .  c o m
     * Generates a HTML "link" string
     *
     * @param text Text for the link
     * @param tooltip Tooltip for the link
     * @param url URL for the link
     * @param styleClass CSS class to attach to the link
     * @param target target for the link
     *
     * @return a HTML "link" string for the given parameters
     */
    public static String linkHtml(String text, String tooltip, String url,
            String styleClass, String target) {

        StringBuffer html = new StringBuffer();

        html.append("<a ");

        if (styleClass != null)
            html.append("class=\"" + styleClass + "\" ");

        html.append("href=\"" + url + "\" ");

        if (tooltip != null)
            html.append("title=\"" + tooltip + "\" ");

        if (target != null)
            html.append("target=\"" + target + "\"");

        html.append(">" + text + "</a>");

        return html.toString();

    }
}

Related Tutorials