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