BookmarkedURL.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.bookmarks;

  18. /**
  19.  * Represents one instance of a URL defined using XEP-0048 Bookmark Storage XEP.
  20.  *
  21.  * @author Derek DeMoro
  22.  */
  23. public class BookmarkedURL implements SharedBookmark {

  24.     private String name;
  25.     private final String URL;
  26.     private boolean isRss;
  27.     private boolean isShared;

  28.     protected BookmarkedURL(String URL) {
  29.         this.URL = URL;
  30.     }

  31.     protected BookmarkedURL(String URL, String name, boolean isRss) {
  32.         this.URL = URL;
  33.         this.name = name;
  34.         this.isRss = isRss;
  35.     }

  36.     /**
  37.      * Returns the name representing the URL (eg. Jive Software). This can be used in as a label, or
  38.      * identifier in applications.
  39.      *
  40.      * @return the name representing the URL.
  41.      */
  42.     public String getName() {
  43.         return name;
  44.     }

  45.     /**
  46.      * Sets the name representing the URL.
  47.      *
  48.      * @param name the name.
  49.      */
  50.     protected void setName(String name) {
  51.         this.name = name;
  52.     }

  53.     /**
  54.      * Returns the URL.
  55.      *
  56.      * @return the url.
  57.      */
  58.     public String getURL() {
  59.         return URL;
  60.     }
  61.     /**
  62.      * Set to true if this URL is an RSS or news feed.
  63.      *
  64.      * @param isRss True if the URL is a news feed and false if it is not.
  65.      */
  66.     protected void setRss(boolean isRss) {
  67.         this.isRss = isRss;
  68.     }

  69.     /**
  70.      * Returns true if this URL is a news feed.
  71.      *
  72.      * @return Returns true if this URL is a news feed.
  73.      */
  74.     public boolean isRss() {
  75.         return isRss;
  76.     }

  77.     @Override
  78.     public boolean equals(Object obj) {
  79.         if (!(obj instanceof BookmarkedURL)) {
  80.             return false;
  81.         }
  82.         BookmarkedURL url = (BookmarkedURL) obj;
  83.         return url.getURL().equalsIgnoreCase(URL);
  84.     }

  85.     @Override
  86.     public int hashCode() {
  87.         return getURL().hashCode();
  88.     }

  89.     protected void setShared(boolean shared) {
  90.         this.isShared = shared;
  91.     }

  92.     @Override
  93.     public boolean isShared() {
  94.         return isShared;
  95.     }
  96. }