Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.IOException;

import java.io.Writer;

public class Main {
    /**
     * Appends str to <code>out</code> while performing HTML attribute escaping.
     * 
     * @param out
     * @param str
     * @throws IOException
     */
    public static void escapeHTMLAttribute(Writer out, String str) throws IOException {
        if (out == null) {
            throw new IllegalArgumentException("The Writer must not be null");
        }
        if (str == null) {
            return;
        }
        int sz;
        sz = str.length();
        for (int i = 0; i < sz; i++) {
            char ch = str.charAt(i);

            switch (ch) {
            case '&':
                out.write("&amp;");
                break;
            case '"':
                out.write("&quot;");
                break;
            case '\t':
                out.write("&#9;");
                break;
            case '\n':
                out.write("&#10;");
                break;
            case '\r':
                out.write("&#13;");
                break;
            case '<':
                out.write("&lt;");
                break;
            case '>':
                out.write("&gt;");
                break;
            default:
                out.write(ch);
                break;
            }

        }
    }
}