Home | History | Annotate | Download | only in picasa
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.cooliris.picasa;
     18 
     19 import org.xml.sax.Attributes;
     20 
     21 /**
     22  * This class models the album entry kind in the Picasa GData API.
     23  */
     24 @Entry.Table("albums")
     25 public final class AlbumEntry extends Entry {
     26     public static final EntrySchema SCHEMA = new EntrySchema(AlbumEntry.class);
     27 
     28     /**
     29      * The user account that is the sync source for this entry. Must be set
     30      * before insert/update.
     31      */
     32     @Column(Columns.SYNC_ACCOUNT)
     33     public String syncAccount;
     34 
     35     /**
     36      * The ETag for the album/photos GData feed.
     37      */
     38     @Column(Columns.PHOTOS_ETAG)
     39     public String photosEtag = null;
     40 
     41     /**
     42      * True if the contents of the album need to be synchronized. Must be set
     43      * before insert/update.
     44      */
     45     @Column(Columns.PHOTOS_DIRTY)
     46     public boolean photosDirty;
     47 
     48     /**
     49      * The "edit" URI of the album.
     50      */
     51     @Column(Columns.EDIT_URI)
     52     public String editUri;
     53 
     54     /**
     55      * The album owner.
     56      */
     57     @Column(Columns.USER)
     58     public String user;
     59 
     60     /**
     61      * The title of the album.
     62      */
     63     @Column(value = Columns.TITLE)
     64     public String title;
     65 
     66     /**
     67      * A short summary of the contents of the album.
     68      */
     69     @Column(value = Columns.SUMMARY)
     70     public String summary;
     71 
     72     /**
     73      * The date the album was created.
     74      */
     75     @Column(Columns.DATE_PUBLISHED)
     76     public long datePublished;
     77 
     78     /**
     79      * The date the album was last updated.
     80      */
     81     @Column(Columns.DATE_UPDATED)
     82     public long dateUpdated;
     83 
     84     /**
     85      * The date the album entry was last edited. May be more recent than
     86      * dateUpdated.
     87      */
     88     @Column(Columns.DATE_EDITED)
     89     public long dateEdited;
     90 
     91     /**
     92      * The number of photos in the album.
     93      */
     94     @Column(Columns.NUM_PHOTOS)
     95     public int numPhotos;
     96 
     97     /**
     98      * The number of bytes of storage that this album uses.
     99      */
    100     @Column(Columns.BYTES_USED)
    101     public long bytesUsed;
    102 
    103     /**
    104      * The user-specified location associated with the album.
    105      */
    106     @Column(Columns.LOCATION_STRING)
    107     public String locationString;
    108 
    109     /**
    110      * The thumbnail URL associated with the album.
    111      */
    112     @Column(Columns.THUMBNAIL_URL)
    113     public String thumbnailUrl;
    114 
    115     /**
    116      * A link to the HTML page associated with the album.
    117      */
    118     @Column(Columns.HTML_PAGE_URL)
    119     public String htmlPageUrl;
    120 
    121     /**
    122      * Column names specific to album entries.
    123      */
    124     public static final class Columns extends PicasaApi.Columns {
    125         public static final String PHOTOS_ETAG = "photos_etag";
    126         public static final String USER = "user";
    127         public static final String BYTES_USED = "bytes_used";
    128         public static final String NUM_PHOTOS = "num_photos";
    129         public static final String LOCATION_STRING = "location_string";
    130         public static final String PHOTOS_DIRTY = "photos_dirty";
    131     }
    132 
    133     /**
    134      * Resets values to defaults for object reuse.
    135      */
    136     @Override
    137     public void clear() {
    138         super.clear();
    139         syncAccount = null;
    140         photosDirty = false;
    141         editUri = null;
    142         user = null;
    143         title = null;
    144         summary = null;
    145         datePublished = 0;
    146         dateUpdated = 0;
    147         dateEdited = 0;
    148         numPhotos = 0;
    149         bytesUsed = 0;
    150         locationString = null;
    151         thumbnailUrl = null;
    152         htmlPageUrl = null;
    153     }
    154 
    155     /**
    156      * Sets the property value corresponding to the given XML element, if
    157      * applicable.
    158      */
    159     @Override
    160     public void setPropertyFromXml(String uri, String localName, Attributes attrs, String content) {
    161         char localNameChar = localName.charAt(0);
    162         if (uri.equals(GDataParser.GPHOTO_NAMESPACE)) {
    163             switch (localNameChar) {
    164             case 'i':
    165                 if (localName.equals("id")) {
    166                     id = Long.parseLong(content);
    167                 }
    168                 break;
    169             case 'u':
    170                 if (localName.equals("user")) {
    171                     user = content;
    172                 }
    173                 break;
    174             case 'n':
    175                 if (localName.equals("numphotos")) {
    176                     numPhotos = Integer.parseInt(content);
    177                 }
    178                 break;
    179             case 'b':
    180                 if (localName.equals("bytesUsed")) {
    181                     bytesUsed = Long.parseLong(content);
    182                 }
    183                 break;
    184             }
    185         } else if (uri.equals(GDataParser.ATOM_NAMESPACE)) {
    186             switch (localNameChar) {
    187             case 't':
    188                 if (localName.equals("title")) {
    189                     title = content;
    190                 }
    191                 break;
    192             case 's':
    193                 if (localName.equals("summary")) {
    194                     summary = content;
    195                 }
    196                 break;
    197             case 'p':
    198                 if (localName.equals("published")) {
    199                     datePublished = GDataParser.parseAtomTimestamp(content);
    200                 }
    201                 break;
    202             case 'u':
    203                 if (localName.equals("updated")) {
    204                     dateUpdated = GDataParser.parseAtomTimestamp(content);
    205                 }
    206                 break;
    207             case 'l':
    208                 if (localName.equals("link")) {
    209                     String rel = attrs.getValue("", "rel");
    210                     String href = attrs.getValue("", "href");
    211                     if (rel.equals("alternate") && attrs.getValue("", "type").equals("text/html")) {
    212                         htmlPageUrl = href;
    213                     } else if (rel.equals("edit")) {
    214                         editUri = href;
    215                     }
    216                 }
    217                 break;
    218             }
    219         } else if (uri.equals(GDataParser.APP_NAMESPACE)) {
    220             if (localName.equals("edited")) {
    221                 dateEdited = GDataParser.parseAtomTimestamp(content);
    222             }
    223         } else if (uri.equals(GDataParser.MEDIA_RSS_NAMESPACE)) {
    224             if (localName == "thumbnail") {
    225                 thumbnailUrl = attrs.getValue("", "url");
    226             }
    227         }
    228     }
    229 }
    230