001package ch.gbrain.gwtstorage.model;
002
003/*
004 * #%L
005 * GwtStorage
006 * %%
007 * Copyright (C) 2016 gbrain.ch
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023public class StorageResource
024{
025  private static String RESOURCEKEYPREFIX = "resource-";
026  private static String RESOURCEKEYVERSIONSUFFIX = "-v";
027
028  String resourceUrl;
029  Integer version;
030
031  public StorageResource(String url, Integer version)
032  {
033    this.resourceUrl = url;
034    this.version = version;
035  }
036
037  public String getResourceIdKey()
038  {
039    return RESOURCEKEYPREFIX + resourceUrl;
040  }
041
042  public String getResourceVersionKey()
043  {
044    return getResourceVersionKey(getResourceIdKey());
045  }
046
047  public static String getResourceVersionKey(String resourceKey)
048  {
049    return resourceKey + RESOURCEKEYVERSIONSUFFIX;
050  }
051
052  public static boolean isResourceKey(String key)
053  {
054    if (key == null) return false;
055    if (key.startsWith(RESOURCEKEYPREFIX)) return true;
056    return false;
057  }
058
059  public static boolean isResourceIdKey(String key)
060  {
061    if (key == null) return false;
062    if (isResourceKey(key) && !key.endsWith(RESOURCEKEYVERSIONSUFFIX)) return true;
063    return false;
064  }
065
066  public static boolean isResourceVersionKey(String key)
067  {
068    if (key == null) return false;
069    if (isResourceKey(key) && key.endsWith(RESOURCEKEYVERSIONSUFFIX)) return true;
070    return false;
071  }
072
073  public String getResourceUrl()
074  {
075    return resourceUrl;
076  }
077
078  public Integer getVersion()
079  {
080    return version;
081  }
082
083}