From: Giovanni Mascellani Subject: [PATCH] patch/XMLCharacterProperties.java Substitute for XMLCharacterProperties.java, which is not compatible with LGPL. Signed-off-by: Giovanni Mascellani --- .../freehep/xml/util/XMLCharacterProperties.java | 80 ++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/src/main/java/org/freehep/xml/util/XMLCharacterProperties.java b/src/main/java/org/freehep/xml/util/XMLCharacterProperties.java new file mode 100644 index 0000000..25295cd --- /dev/null +++ b/src/main/java/org/freehep/xml/util/XMLCharacterProperties.java @@ -0,0 +1,80 @@ +/* + * Copyright 2010 by Giovanni Mascellani + * + * This class is meant as a substitute for the original XMLCharacterProperties + * in FreeHEP-XML, which is picked out from Xerces, but it licensed + * under Apache 1.1 license (GPL-incompatible). IT IS NOT A COMPLETE + * REPLACEMENT: it just implements the three methods needed by JAS Plotter. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +package org.freehep.xml.util; + +public class XMLCharacterProperties { + + public static boolean isLetter(char c) { + return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')); + } + + public static boolean isDigit(char c) { + return (c >= '0') && (c <= '9'); + } + + /* + * [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+ + */ + public static boolean validVersionNum(String name) { + int len = name.length(); + if (len == 0) return false; + for (int i = 0; i < len; i++) { + char c = name.charAt(i); + if (!(isLetter(c) || isDigit(c) || c == '_' || c == '.' || c == ':' || c == '-')) return false; + } + return true; + } + + /* + * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* + */ + public static boolean validEncName(String name) { + int len = name.length(); + if (len == 0) return false; + if (!isLetter(name.charAt(0))) return false; + for (int i = 1; i < len; i++) { + char c = name.charAt(i); + if (!(isLetter(c) || isDigit(c) || c == '.' || c == '_' || c == '-')) return false; + } + return true; + } + + /* + * [5] Name ::= (Letter | '_' | ':') (NameChar)* + */ + public static boolean validName(String name) { + int len = name.length(); + if (len == 0) return false; + char c = name.charAt(0); + if (!(isLetter(c) || c == '_' || c == ':')) return false; + for (int i = 1; i < len; i++) { + c = name.charAt(i); + if (!(isLetter(c) || isDigit(c) || c == '_' || c == '.' || c == ':' || c == '-')) return false; + } + return true; + } + +} + -- tg: (6d7665d..) patch/XMLCharacterProperties.java (depends on: master)