Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 Copyright 2008 San Jose State University
    
 This file is part of the Blackberry Cinequest client.
    
 The Blackberry Cinequest client is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 The Blackberry Cinequest client is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with the Blackberry Cinequest client.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Hashtable;

public class Main {
    private static Hashtable replacements = new Hashtable();

    /**
     * Replaces HTML entities in a string buffer
     * @param buffer the string buffer
     */
    public static void replaceEntities(StringBuffer buffer) {
        int i = 0;
        while (i < buffer.length()) {
            if (buffer.charAt(i) == '&') {
                int j = i + 1;
                while (j < buffer.length() && buffer.charAt(j) != ';')
                    j++;
                if (j < buffer.length()) {
                    char[] chars = new char[j - i - 1];
                    buffer.getChars(i + 1, j, chars, 0);
                    Character repl = (Character) replacements.get(new String(chars));
                    if (repl != null) {
                        buffer.delete(i, j);
                        buffer.setCharAt(i, repl.charValue());
                    } else
                        i = j;
                } else
                    i = j;
            }
            i++;
        }
    }
}