Android Open Source - Locast-Core-Android Abs Resources Sync






From Project

Back to project page Locast-Core-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Locast-Core-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.mit.mobile.android.locast.data;
//w w  w . j a v  a 2  s .co m
import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import edu.mit.mobile.android.locast.data.JsonSyncableItem.SyncCustom;
import edu.mit.mobile.android.locast.net.NetworkProtocolException;

/**
 * Abstract resource sync.
 *
 * @author steve
 *
 */
public abstract class AbsResourcesSync extends SyncCustom {

    public static final String DEFAULT_REMOTE_KEY = "resources";
    public static final String DEFAULT_REMOTE_MIME_TYPE_KEY = "mime_type";
    public static final String DEFAULT_REMOTE_URL_KEY = "url";
    public static final int DEFAULT_FLAGS = FLAG_OPTIONAL;

    public AbsResourcesSync() {
        super(DEFAULT_REMOTE_KEY, DEFAULT_FLAGS);
    }

    public AbsResourcesSync(String remoteKey) {
        super(remoteKey, DEFAULT_FLAGS);
    }

    public AbsResourcesSync(String remoteKey, int flags) {
        super(remoteKey, flags);
    }

    @Override
    public Object toJSON(Context context, Uri localItem, Cursor c, String lProp)
            throws JSONException, NetworkProtocolException, IOException {
        return null;
    }

    @Override
    public ContentValues fromJSON(Context context, Uri localItem, JSONObject item, String lProp)
            throws JSONException, NetworkProtocolException, IOException {
        final ContentValues cv = new ContentValues();

        final JSONObject resourcesJo = item.getJSONObject(remoteKey);

        fromResourcesJSON(context, localItem, cv, resourcesJo);

        return cv;
    }

    /**
     * Implement this to handle loading from JSON. It's easiest to use
     * {@link #addToContentValues(ContentValues, String, JSONObject, String, String, boolean)}
     * here.
     *
     * @param context
     * @param localItem
     * @param cv
     * @param resources
     * @throws NetworkProtocolException
     * @throws JSONException
     */
    protected abstract void fromResourcesJSON(Context context, Uri localItem, ContentValues cv,
            JSONObject resources) throws NetworkProtocolException, JSONException;

    /**
     * Helper method to make it easy to load the standard resource JSON structure to a flattened
     * {@link ContentValues} object. This should be called from your implementation of
     * {@link #fromResourcesJSON(Context, Uri, ContentValues, JSONObject)}.
     *
     * @param cv
     *            destination to store result in
     * @param resourceKey
     *            the key under "resources" to load. Eg. "primary"
     * @param resources
     *            the input object
     * @param localUrlProp
     *            the local key under which the URL part should be stored.
     * @param localMimeTypeProp
     *            the local key under which the MIME type should be stored. Null is ok here to
     *            not store it.
     * @param required
     *            true if this resource is required. A {@link NetworkProtocolException} will be
     *            thrown if it is and the resource is missing.
     * @throws NetworkProtocolException
     * @throws JSONException
     */
    protected void addToContentValues(ContentValues cv, String resourceKey,
            JSONObject resources, String localUrlProp, String localMimeTypeProp,
            boolean required) throws NetworkProtocolException, JSONException {
        if (resources.has(resourceKey)) {
            final JSONObject resourceItemJo = resources.getJSONObject(resourceKey);

            cv.put(localUrlProp, resourceItemJo.getString(DEFAULT_REMOTE_URL_KEY));

            if (localMimeTypeProp != null) {
                cv.put(localMimeTypeProp,
                        resourceItemJo.getString(DEFAULT_REMOTE_MIME_TYPE_KEY));
            }

        } else {
            if (required) {
                throw new NetworkProtocolException("missing resource '" + resourceKey
                        + "' in JSON");
            }
        }
    }
}




Java Source Code List

com.beoui.geocell.GeocellLogger.java
com.beoui.geocell.GeocellQueryEngine.java
com.beoui.geocell.GeocellUtils.java
com.beoui.geocell.annotations.Geocells.java
com.beoui.geocell.annotations.Latitude.java
com.beoui.geocell.annotations.Longitude.java
com.beoui.geocell.comparator.DoubleTupleComparator.java
com.beoui.geocell.comparator.LocationComparableTuple.java
com.beoui.geocell.model.BoundingBox.java
com.beoui.geocell.model.CostFunction.java
com.beoui.geocell.model.DefaultCostFunction.java
com.beoui.geocell.model.GeocellQuery.java
com.beoui.geocell.model.LocationCapable.java
com.beoui.geocell.model.Point.java
com.beoui.geocell.model.Tuple.java
com.stackoverflow.ArrayUtils.java
com.stackoverflow.CollectionUtils.java
com.stackoverflow.MediaUtils.java
com.stackoverflow.Predicate.java
edu.mit.mobile.android.MelAndroid.java
edu.mit.mobile.android.json.JSONArrayAdapter.java
edu.mit.mobile.android.locast.Constants.java
edu.mit.mobile.android.locast.accounts.AbsAccountChangeReceiver.java
edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticationService.java
edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticatorActivity.java
edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticator.java
edu.mit.mobile.android.locast.accounts.AbsRegisterActivity.java
edu.mit.mobile.android.locast.accounts.LogoutFragment.java
edu.mit.mobile.android.locast.app.LocastApplication.java
edu.mit.mobile.android.locast.data.AbsComment.java
edu.mit.mobile.android.locast.data.AbsResourcesSync.java
edu.mit.mobile.android.locast.data.CastMedia.java
edu.mit.mobile.android.locast.data.ImageContent.java
edu.mit.mobile.android.locast.data.JSONSyncableIdenticalChildFinder.java
edu.mit.mobile.android.locast.data.JsonSyncableItem.java
edu.mit.mobile.android.locast.data.MediaProcessingException.java
edu.mit.mobile.android.locast.data.NoPublicPath.java
edu.mit.mobile.android.locast.data.OrderedList.java
edu.mit.mobile.android.locast.data.ResourcesSync.java
edu.mit.mobile.android.locast.data.SyncException.java
edu.mit.mobile.android.locast.data.SyncItemDeletedException.java
edu.mit.mobile.android.locast.data.SyncMapException.java
edu.mit.mobile.android.locast.data.SyncMap.java
edu.mit.mobile.android.locast.data.VideoContent.java
edu.mit.mobile.android.locast.data.interfaces.AuthorableUtils.java
edu.mit.mobile.android.locast.data.interfaces.Authorable.java
edu.mit.mobile.android.locast.data.interfaces.CommentableUtils.java
edu.mit.mobile.android.locast.data.interfaces.Commentable.java
edu.mit.mobile.android.locast.data.interfaces.FavoritableUtils.java
edu.mit.mobile.android.locast.data.interfaces.Favoritable.java
edu.mit.mobile.android.locast.data.interfaces.LocatableUtils.java
edu.mit.mobile.android.locast.data.interfaces.Locatable.java
edu.mit.mobile.android.locast.data.interfaces.PrivatelyAuthorableUtils.java
edu.mit.mobile.android.locast.data.interfaces.PrivatelyAuthorable.java
edu.mit.mobile.android.locast.data.interfaces.TitledUtils.java
edu.mit.mobile.android.locast.data.interfaces.Titled.java
edu.mit.mobile.android.locast.data.tags.IdenticalTagFinder.java
edu.mit.mobile.android.locast.data.tags.TagSyncField.java
edu.mit.mobile.android.locast.data.tags.Tag.java
edu.mit.mobile.android.locast.data.tags.TaggableUtils.java
edu.mit.mobile.android.locast.data.tags.TaggableWrapper.java
edu.mit.mobile.android.locast.data.tags.Taggable.java
edu.mit.mobile.android.locast.net.ClientResponseException.java
edu.mit.mobile.android.locast.net.LocastApplicationCallbacks.java
edu.mit.mobile.android.locast.net.NetworkClient.java
edu.mit.mobile.android.locast.net.NetworkProtocolException.java
edu.mit.mobile.android.locast.sync.AbsLocastAccountSyncService.java
edu.mit.mobile.android.locast.sync.AbsMediaSync.java
edu.mit.mobile.android.locast.sync.LocastSimpleSyncService.java
edu.mit.mobile.android.locast.sync.LocastSyncService.java
edu.mit.mobile.android.locast.sync.LocastSyncStatusObserver.java
edu.mit.mobile.android.locast.sync.NotificationProgressListener.java
edu.mit.mobile.android.locast.sync.SyncColumns.java
edu.mit.mobile.android.locast.sync.SyncEngine.java
edu.mit.mobile.android.locast.sync.SyncableProvider.java
edu.mit.mobile.android.locast.sync.SyncableSimpleContentProvider.java
edu.mit.mobile.android.locast.sync.Syncable.java
edu.mit.mobile.android.locast.widget.RemoteTagsAdapter.java
edu.mit.mobile.android.locast.widget.TagButton.java
edu.mit.mobile.android.locast.widget.TagListView.java
edu.mit.mobile.android.locast.widget.TagList.java
edu.mit.mobile.android.locast.widget.TagsLoaderCallbacks.java
edu.mit.mobile.android.location.IncrementalLocator.java
se.fnord.android.layout.PredicateLayout.java