private void validateString (String queryString) {
//Check if the query string is empty
if (queryString == null || queryString.trim().equals("")) {
throw new InvalidQueryException("Query string must not be empty");
}
//Check if the query string is not composed only by the node delimiter
if (queryString.charAt(0) == NODE_DELIMITER && queryString.substring(1).trim().equals("") ) {
throw new InvalidQueryException("Query string must be composed by one or more nodes.");
}
//Disables queries beginning with a node delimiter
if (queryString.charAt(0) == NODE_DELIMITER) {
queryString = queryString.substring(1);
}
String[] pieces = breakQueryString(queryString);
for (String piece : pieces) {
//Checks if it contains an illegal syntax for declaring elements
if ((piece.contains(String.valueOf(OPEN_NAMESPACE_CHARACTER)) && !piece.contains(String.valueOf(CLOSE_NAMESPACE_CHARACTER))) ||
piece.contains(String.valueOf(CLOSE_NAMESPACE_CHARACTER)) && !piece.contains(String.valueOf(OPEN_NAMESPACE_CHARACTER))){
throw new InvalidQueryException("Namespace declaration in piece " + piece + " is illegal.");
}
if (piece.contains(String.valueOf(OPEN_NAMESPACE_CHARACTER))) {
String namespace = getQueryNamespace(piece);