package ubic.gemma.util;

import org.apache.commons.lang.StringUtils;

/**
 * Used to generate hyperlinks to various things in Gemma.\
 * 
 * @author luke
 * @version $Id$
 */
public class AnchorTagUtil {

    public static String getLink( String url, String link, String hover ) {
        StringBuffer buf = new StringBuffer();
        buf.append( "<a href=\"" );
        buf.append( url );
        buf.append( "\"" );
        if ( hover != null ) {
            buf.append( " class=\"tooltip\"" );
        }
        buf.append( ">" );
        buf.append( link );
        if ( hover != null ) {
            buf.append( "<span class=\"tooltiptext\">" );
            buf.append( hover );
            buf.append( "</span>" );
        }
        buf.append( "</a>" );
        return buf.toString();
    }

    public static String getExpressionExperimentUrl( long eeId ) {
        return String.format( "/Gemma/expressionExperiment/showExpressionExperiment.html?id=%d", eeId );
    }

    public static String getExpressionExperimentLink( Long eeId, String link ) {
        return getExpressionExperimentLink( eeId, link, null );
    }

    public static String getExpressionExperimentLink( Long eeId, String link, String hover ) {
        return getLink( getExpressionExperimentUrl( eeId ), link, hover );
    }

    public static String getExperimentalDesignLink( Long edId, String link ) {
        return getExperimentalDesignLink( edId, link, null );
    }

    public static String getExperimentalDesignLink( Long edId, String link, String hover ) {
        return getLink( String.format( "/Gemma/expressionExperiment/showExperimentalDesign.html?id=%d", edId ),
                "ExperimentalDesign " + ( StringUtils.isBlank( link ) ? "" : ": " + link ), hover );
    }

    public static String getProbeLink( Long probeId, String link ) {
        // FIXME this isn't the greatest page - it's kind of old-style.
        return getLink( String.format( "/Gemma/compositeSequence/show.html?id=%d", probeId ), link, "" );
    }

    public static String getArrayDesignLink( Long adId, String link ) {
        return getArrayDesignLink( adId, link, null );
    }

    public static String getArrayDesignLink( Long adId, String link, String hover ) {
        return getLink( String.format( "Gemma/arrays/showArrayDesign.html?id=%d", adId ), link, hover );
    }

    public static String getBioMaterialLink( Long bmId, String link ) {
        return getBioMaterialLink( bmId, link, null );
    }

    public static String getBioMaterialLink( Long bmId, String link, String hover ) {
        return getLink( String.format( "/Gemma/bioMaterial/showBioMaterial.html?id=%d", bmId ), link, hover );
    }
}

@@ -1294,32 +1294,131 @@
 hover );%0A    %7D%0A%0A
+    /**%0A     * @param eeId Id of the experimental design%0A     * @param link%0A     * @return%0A     */%0A
     public stati
@@ -1451,33 +1451,33 @@
 signLink( Long e
-d
+e
 Id, String link 
@@ -1523,17 +1523,17 @@
 nLink( e
-d
+e
 Id, link
@@ -1541,32 +1541,151 @@
  null );%0A    %7D%0A%0A
+    /**%0A     * @param eeId Id of the experimental design%0A     * @param link%0A     * @param hover%0A     * @return%0A     */%0A
     public stati
@@ -1811,33 +1811,31 @@
 emma/exp
-ressionExperiment
+erimentalDesign
 /showExp
@@ -1847,32 +1847,34 @@
 ntalDesign.html?
+ed
 id=%25d%22, edId ),%0A

fix broken ee design url generation