Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Created on 16/07/2004
 * YAWLEditor v1.01 
 *
 * @author Lindsay Bradford
 * 
 * 
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

public class Main {
    /**
     * Returns whether the string supplied could be used as a valid XML name.
     * @param name The string to test for XML name validity.
     * @return true if the string can be used as a valid XML name, false otherwise.
     */
    public static boolean isValidXMLName(String name) {
        String trimmedName = name.trim();

        boolean currentCharacterValid;

        if (name == null || trimmedName.length() == 0) {
            return false;
        }

        // ensure that XML standard reserved names are not used

        if (trimmedName.toUpperCase().startsWith("XML")) {
            return false;
        }

        // test that name starts with a valid XML name-starting character

        if (!Character.isUpperCase(trimmedName.charAt(0)) && !Character.isLowerCase(trimmedName.charAt(0))
                && trimmedName.charAt(0) != '_') {
            return false;
        }

        // test that remainder name chars are a valid XML name characters 

        if (name.trim().length() > 0) {
            for (int i = 1; i < trimmedName.length(); i++) {
                currentCharacterValid = false;

                if (Character.isUpperCase(trimmedName.charAt(i)) || Character.isLowerCase(trimmedName.charAt(i))
                        || Character.isDigit(trimmedName.charAt(i))) {
                    currentCharacterValid = true;
                }

                if (trimmedName.charAt(i) == '_' || trimmedName.charAt(i) == '-' || trimmedName.charAt(i) == '.') {
                    currentCharacterValid = true;
                }

                if (!currentCharacterValid) {
                    return false;
                }
            }
        }
        return true;
    }
}