2 * Copyright (C) 2012 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 * @author Murray Cumming <murrayc@murrayc.com>
33 public abstract class HasDocumentPlace extends Place {
35 protected final String documentID;
40 public HasDocumentPlace(final String documentID) {
42 this.documentID = documentID;
45 public String getDocumentID() {
49 public static class Tokenizer {
50 protected final String documentKey = "document";
51 private final String equals = "=";
52 private final String separator = "&";
55 * Get a HashMap of parameter names and values from the history token. This can parse tokens built by
59 * The historyToken provided to getPlace().
60 * @return A HasMap of names to values.
62 protected HashMap<String, String> getTokenParams(final String historyToken) {
63 final String[] arStr = historyToken.substring(0, historyToken.length()).split(separator);
64 final HashMap<String, String> params = new HashMap<String, String>();
65 for (final String element : arStr) {
66 final String[] substr = element.split(equals);
67 if (substr.length != 2) {
73 if (!StringUtils.isEmpty(substr[0])) {
77 if (!StringUtils.isEmpty(substr[1])) {
81 if (!StringUtils.isEmpty(key) && !StringUtils.isEmpty(value)) {
82 params.put(key, value);
90 * Build a history token based on a HashMap of parameter names and values. This can later be parsed by
94 * A HashMap of names and values.
95 * @return A history string for use by getToken() implementation.
97 protected String buildParamsToken(final HashMap<String, String> params) {
99 for (final Map.Entry<String, String> entry : params.entrySet()) {
100 final String key = entry.getKey();
101 final String value = entry.getValue();
102 if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
110 token += key + equals + value;