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;
25 import org.glom.web.client.StringUtils;
27 import com.google.gwt.place.shared.Place;
30 * Super type for Place objects (bookmarkable URLs) that display the TableSelectionView.
33 public abstract class HasTablePlace extends Place {
35 private final String documentID;
36 private final String tableName;
38 public HasTablePlace(final String documentID, final String tableName) {
39 this.documentID = documentID;
40 this.tableName = tableName;
43 public String getDocumentID() {
47 public String getTableName() {
51 public static class Tokenizer {
52 protected final String documentKey = "document";
53 protected final String tableKey = "table";
54 private final String separator = "&";
55 private final String equals = "=";
58 * Get a HashMap of parameter names and values from the history token. This can parse tokens built by
62 * The historyToken provided to getPlace().
63 * @return A HasMap of names to values.
65 protected HashMap<String, String> getTokenParams(final String historyToken) {
66 final String[] arStr = historyToken.substring(0, historyToken.length()).split(separator);
67 final HashMap<String, String> params = new HashMap<String, String>();
68 for (String element : arStr) {
69 final String[] substr = element.split(equals);
70 if (substr.length != 2) {
76 if (!StringUtils.isEmpty(substr[0])) {
80 if (!StringUtils.isEmpty(substr[1])) {
84 if (!StringUtils.isEmpty(key) && !StringUtils.isEmpty(value)) {
85 params.put(key, value);
93 * Build a history token based on a HashMap of parameter names and values. This can later be parsed by
97 * A HashMap of names and values.
98 * @return A history string for use by getToken() implementation.
100 protected String buildParamsToken(final HashMap<String, String> params) {
102 for (Map.Entry<String, String> entry : params.entrySet()) {
103 final String key = entry.getKey();
104 final String value = entry.getValue();
105 if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
113 token += key + equals + value;