1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.common.uri;
14 import java.util.regex.Pattern;
19 private static final String HTTP = "http:/";
20 private static final String HTTP_SLASH = "http://";
22 private static final Pattern slash = Pattern.compile("/");
25 * Escapes the specified name by changing spaces (' ') into underscores
28 * @param name name to escape
30 * @deprecated do not use, this is not the DB standard to URI escaping.
33 public static String escapeName(String name) {
34 char[] chars = name.toCharArray();
35 boolean modified = false;
36 for(int i=0;i<chars.length;++i)
37 if(!Character.isJavaIdentifierPart(chars[i])) {
42 return new String(chars);
47 public static String[] splitURI(String uri) {
48 if(!uri.startsWith(HTTP_SLASH))
49 throw new IllegalArgumentException("Uri does not begin with '" + HTTP_SLASH + "'. given uri: " + uri);
50 return slash.split(uri.substring(7));
53 public static String joinURI(String[] names) {
54 StringBuilder b = new StringBuilder();
56 for(String name : names) {