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.layer0.utils.direct;
14 import org.simantics.databoard.util.URIStringUtils;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.exception.ServiceException;
19 import org.simantics.db.exception.ValidationException;
20 import org.simantics.layer0.Layer0;
21 import org.simantics.layer0.utils.PropertyReference;
23 public final class ResourceNameUtils {
25 public static final char NAME_PATH_DELIMITER = '/';
26 public static final String NAME_PATH_DELIMITER_STRING = "" + NAME_PATH_DELIMITER;
28 public static String getName(ReadGraph g, Resource r) throws ValidationException, ServiceException {
29 Layer0 b = Layer0.getInstance(g);
30 String name = (String) g.getPossibleRelatedValue(r, b.HasName);
32 return "#" + r.getResourceId();
34 return URIStringUtils.escape(name);
37 public static String getName(ReadGraph g, PropertyReference ref) throws DatabaseException {
38 return getName(g, ref.resources);
41 public static String getName(ReadGraph g, Resource[] ref) throws DatabaseException {
42 StringBuilder b = new StringBuilder();
44 for (Resource r : ref) {
48 b.append(NAME_PATH_DELIMITER);
49 b.append(getName(g, r));