This project has retired. For details please refer to its
Attic page.
NameValidator xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */1920package org.apache.chemistry.opencmis.inmemory;
2122publicclassNameValidator {
2324publicstaticfinal String ERROR_ILLEGAL_ID = "Id contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_'";
25publicstaticfinal String ERROR_ILLEGAL_NAME = "Name contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_', '.', ' '";
2627// Utility class28privateNameValidator() {
29 }
3031/**32 * check whether id contains only valid characters Allowed are 'a'..'z',33 * 'A'..'Z', '0'..'9', '.', '-', ' ', '_';34 *35 * @param s36 * string to verify37 */38publicstaticboolean isValidId(String s) {
39if (null == s || s.length() == 0) {
40return false;
41 }
4243if (s.startsWith("cmis:")) {
44 s = s.substring(5);
45 }
4647for (int i = 0; i < s.length(); i++) {
48char c = s.charAt(i);
49if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-'
50 || c == '_' || c == ' ')) {
51return false;
52 }
53 }
54returntrue;
55 }
5657publicstaticboolean isValidLocalName(String s) {
58return isValidId(s);
59 }
6061/**62 * check whether id contains only valid characters Allowed are 'a'..'z',63 * 'A'..'Z', '0'..'9', '.', '-', ' ', '_';64 *65 * @param s66 * string to verify67 */68publicstaticboolean isValidName(String s) {
69if (null == s || s.length() == 0) {
70return false;
71 }
72for (int i = 0; i < s.length(); i++) {
73char c = s.charAt(i);
74if (c == '\\' || c == '/' || c == '\'' || c == '\"' || c == ':' || c == '*' ||
75 c == '?' ||c == '<' || c == '>' && c == '|')
76return false;
77 }
78returntrue;
79 }
8081publicstaticboolean isValidNamespace(String s) {
82return isValidId(s);
83 }
8485publicstaticboolean isValidQueryName(String s) {
86return isValidId(s);
87 }
8889 }