2 * Copyright (C) 2011 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.client.place;
22 import java.util.HashMap;
23 import java.util.Iterator;
25 import java.util.Map.Entry;
27 import org.glom.web.client.StringUtils;
29 import com.google.gwt.place.shared.Place;
32 * Super type for Place objects (bookmarkable URLs) that display the TableSelectionView.
35 public abstract class HasTablePlace extends Place {
37 private final String documentID;
38 private final String tableName;
40 public HasTablePlace(final String documentID, final String tableName) {
41 this.documentID = documentID;
42 this.tableName = tableName;
45 public String getDocumentID() {
49 public String getTableName() {
53 public static class Tokenizer {
54 protected final String documentKey = "document";
55 protected final String tableKey = "table";
56 private final String separator = "&";
57 private final String equals = "=";
60 * Get a HashMap of parameter names and values from the history token. This can parse tokens built by
64 * The historyToken provided to getPlace().
65 * @return A HasMap of names to values.
67 protected HashMap<String, String> getTokenParams(final String historyToken) {
68 final String[] arStr = historyToken.substring(0, historyToken.length()).split(separator);
69 final HashMap<String, String> params = new HashMap<String, String>();
70 for (int i = 0; i < arStr.length; i++) {
71 final String[] substr = arStr[i].split(equals);
72 if (substr.length != 2) {
78 if (!StringUtils.isEmpty(substr[0])) {
82 if (!StringUtils.isEmpty(substr[1])) {
86 if (!StringUtils.isEmpty(key) && !StringUtils.isEmpty(value)) {
87 params.put(key, value);
95 * Build a history token based on a HashMap of parameter names and values. This can later be parsed by
99 * A HashMap of names and values.
100 * @return A history string for use by getToken() implementation.
102 protected String buildParamsToken(final HashMap<String, String> params) {
104 for (final Iterator<Entry<String, String>> it = params.entrySet().iterator(); it.hasNext();) {
105 final Map.Entry<String, String> entry = it.next();
106 final String key = entry.getKey();
107 final String value = entry.getValue();
108 if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value))
115 token += key + equals + value;