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