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.graphviz;
\r
14 import java.io.PrintStream;
\r
15 import java.util.HashMap;
\r
16 import java.util.Map;
\r
19 * Default implementation for IAttributeContainer.
\r
21 * @author Hannu Niemistö
\r
23 public class AbstractAttributeContainer implements IAttributeContainer {
\r
25 Map<String,String> attributes = new HashMap<String,String>();
\r
27 public void set(String key, String value) {
\r
28 attributes.put(key, value);
\r
31 public String get(String key) {
\r
32 return attributes.get(key);
\r
35 protected void writeAttributes(PrintStream s) {
\r
37 boolean first = true;
\r
38 for(Map.Entry<String, String> ent : attributes.entrySet()) {
\r
39 String key = ent.getKey();
\r
40 String value = ent.getValue();
\r
46 if(!value.isEmpty() && value.charAt(0) == '<' && value.charAt(value.length()-1) == '>') {
\r
52 s.print(escape(value));
\r
59 static String escape(String str) {
\r
60 str = str.replace("\"", "\\\"");
\r