ExplanationTextFormater

This class is an example for class that can be usefull to generate valid html code when setting the explanation for an program-problem manually in the evaluator

package net.mumie.comaTools;

/**  
 * This class gives you some tools to reformat the String you want to set as
 * explanation, when the correction of a<br/>
 * <br/>
 * \documentclass{mumie.problem.program}<br/>
 * <br/>
 * has been processed completely.
 * 
 * @author Robert Rudow
 * 
 */ 
public class ExplanationTextFormater  
{  
    /**  
     * replaces java linebreaks with html linebreaks  
     *   
     * @param output 
     *            the outputText that shall be used as explanation for the  
     *            correction  
     * @return the reformated text  
     */  
    public static String replaceLineBreaks(String output)  
    {   
        if (output == null)   
            return "";  
        else  
        {  
            return output.replaceAll("\n", newLine()); 
        }  
    } 

    /**  
     * replaces the special characters <br/> 
     * &amp;, &lt;, &gt;, &quot;<br/>  
     * &auml;, &ouml;, &uuml;, &Auml;, &Ouml;, &Uuml;, &szlig;<br/> 
     * <br/>  
     * with its html representation.
     *   
     * @param output  
     *            the outputText that shall be used as explanation for the 
     *            correction 
     * @return the reformated text  
     */ 
    public static String replaceSpecialCharacters(String output)  
    {  
        if (output == null)  
            return "";  

        String tmp = new String(output);  

        String[] original = { "&", "<", ">", "\"", "ä", "ö", "ü", "Ä", "Ö", "Ü", "ß" };  
        String[] replacement = { "&amp;", "&lt;", "&gt;", "&quot;", "&auml;", "&ouml;", "&uuml;", "&Auml;", "&Ouml;", "&Uuml;", "&szlig;" };

        for (int i = 0; i < original.length; i++)
        { 
            tmp = tmp.replaceAll(original[i], replacement[i]);
        }  

        return tmp;   
    }  

    /** 
     * replaces the output that way that it will be displayed in 
     * html-programlisting-verbatim.<br/> 
     * <br/>
     * Example: 
     * 
     * &lt;pre class="programlisting"&gt; 
     *  &amp;lt;pre&amp;gt;
     *    10 PRINT "BASIC IS OVER FORTY YEARS OLD!"  
     *    20 GOTO 10 
     *    30 END  
     *  &amp;lt;/pre&amp;gt;
     * &lt;/pre&gt; 
     * 
     * @param output 
     *            he outputText that shall be used as explanation for the
     *            correction
     * @return the reformated text 
     */
    public static String addVerbatimProgramlistingEnvironment(String output)
    { 
        if (output == null)
            return ""; 

        return "&lt;pre class=\"programlisting\"&gt;" + output + "&lt;/pre&gt;"; 
    }

    /** 
     * replaces the output that way that it will be displayed in 
     * html-block-verbatim.&lt;br/&gt;
     * &lt;br/&gt; 
     * Example: 
     *  
     * &lt;pre class="block"&gt;
     *  &amp;lt;pre&amp;gt; 
     *    10 PRINT "BASIC IS OVER FORTY YEARS OLD!"  
     *    20 GOTO 10 
     *    30 END  
     *  &amp;lt;/pre&amp;gt; 
     * &lt;/pre&gt; 
     *  
     * @param output
     *           he outputText that shall be used as explanation for the
     *            correction
     * @return the reformated text
     */
    public static String addVerbatimBlockEnvironment(String output)
    {
        if (output == null)
            return "";

        return "&lt;pre class=\"block\"&gt;" + output + "&lt;/pre&gt;";
    }

    /**
     * gives you a hard html linebreak
     * 
     * @return html linebreak
     */
    public static String newLine()
    {
        return "&lt;"+"br/"+"&gt;";
    }
}

Add picture from clipboard (Maximum size: 500 MB)