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.request;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.ResourceSet;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.layer0.Layer0;
23 public class TypeString extends BinaryRead<ResourceSet, String, String> {
25 final private Layer0 L0;
27 public TypeString(Layer0 L0, Set<Resource> set) {
28 super((ResourceSet)set, " ");
32 // public TypeString(Layer0 L0, ResourceSet set, String separator) {
33 // super(set, separator);
34 // if (separator == null)
35 // throw new NullPointerException("null separator");
40 public String perform(ReadGraph graph) throws DatabaseException {
42 if (parameter == null || parameter.isEmpty()) return "";
44 StringBuilder result = new StringBuilder();
47 for(Resource r : parameter) {
48 String name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);
50 if(!first) result.append(parameter2);
52 result.append(escapeToken(name));
56 return result.toString();
60 public static String escapeToken(String token) {
61 return token.replaceAll("( |\\\\)", "\\\\$0");