Android Open Source - cirrus N D F D Request From Project Back to project page cirrus .
License The source code is released under:
Apache License
If you think the Android project cirrus 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 com.inktomi.cirrus;
/ / w w w . j a v a 2 s . c o m
import android.util.Log;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.inktomi.cirrus.forecast.WeatherResponse;
import com.inktomi.cirrus.forecast.Error;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.ElementException;
import org.simpleframework.xml.core.Persister;
import org.simpleframework.xml.transform.Matcher;
import org.simpleframework.xml.transform.Transform;
import java.util.Date;
/**
* Parses the XML that we get from the NDFD
*/
public class NDFDRequest extends Request<WeatherResponse> {
private static final String TAG = NDFDRequest.class.getName();
private Serializer mSerializer = new Persister(new Matcher() {
public Transform match(Class type) throws Exception {
if (type.isEnum()) {
return new EnumTransform(type);
}
if ( type == Date.class ){
return new DateTransform();
}
return null;
}
});
private final Response.Listener<WeatherResponse> mListener;
public NDFDRequest(int method, String url, Response.ErrorListener errorListener, Response.Listener<WeatherResponse> mListener) {
super (method, url, errorListener);
this.mListener = mListener;
}
@Override
protected Response<WeatherResponse> parseNetworkResponse(NetworkResponse response) {
WeatherResponse rval;
try {
rval = mSerializer.read(WeatherResponse.class, new String(response.data));
} catch (ElementException e){
Log.e(TAG, "Failed to read DWML format. Trying error class." , e);
try {
Error errorResponse = mSerializer.read(Error.class, new String(response.data));
return Response.error(new VolleyError(errorResponse.message.body));
} catch (Exception e1) {
Log.e(TAG, "Failed to read DWML format." , e);
return Response.error(new VolleyError(e.getMessage(), e));
}
} catch (Exception e) {
Log.e(TAG, "Failed to read DWML format." , e);
return Response.error(new VolleyError(e.getMessage(), e));
}
return Response.success(rval, HttpHeaderParser.parseCacheHeaders(response));
}
@Override
protected void deliverResponse(WeatherResponse response) {
mListener.onResponse(response);
}
}
Java Source Code List com.android.volley.AuthFailureError.java com.android.volley.CacheDispatcher.java com.android.volley.Cache.java com.android.volley.DefaultRetryPolicy.java com.android.volley.ExecutorDelivery.java com.android.volley.NetworkDispatcher.java com.android.volley.NetworkError.java com.android.volley.NetworkResponse.java com.android.volley.Network.java com.android.volley.NoConnectionError.java com.android.volley.ParseError.java com.android.volley.RequestQueue.java com.android.volley.Request.java com.android.volley.ResponseDelivery.java com.android.volley.Response.java com.android.volley.RetryPolicy.java com.android.volley.ServerError.java com.android.volley.TimeoutError.java com.android.volley.VolleyError.java com.android.volley.VolleyLog.java com.android.volley.toolbox.AndroidAuthenticator.java com.android.volley.toolbox.Authenticator.java com.android.volley.toolbox.BasicNetwork.java com.android.volley.toolbox.ByteArrayPool.java com.android.volley.toolbox.ClearCacheRequest.java com.android.volley.toolbox.DiskBasedCache.java com.android.volley.toolbox.HttpClientStack.java com.android.volley.toolbox.HttpHeaderParser.java com.android.volley.toolbox.HttpStack.java com.android.volley.toolbox.HurlStack.java com.android.volley.toolbox.ImageLoader.java com.android.volley.toolbox.ImageRequest.java com.android.volley.toolbox.JsonArrayRequest.java com.android.volley.toolbox.JsonObjectRequest.java com.android.volley.toolbox.JsonRequest.java com.android.volley.toolbox.NetworkImageView.java com.android.volley.toolbox.NoCache.java com.android.volley.toolbox.PoolingByteArrayOutputStream.java com.android.volley.toolbox.RequestFuture.java com.android.volley.toolbox.StringRequest.java com.android.volley.toolbox.Volley.java com.inktomi.cirrus.BitmapLruCache.java com.inktomi.cirrus.CirrusClient.java com.inktomi.cirrus.DateTransform.java com.inktomi.cirrus.EnumTransform.java com.inktomi.cirrus.NDFDRequest.java com.inktomi.cirrus.SampleActivity.java com.inktomi.cirrus.URLStrings.java com.inktomi.cirrus.WeatherUtils.java com.inktomi.cirrus.forecast.Anomaly.java com.inktomi.cirrus.forecast.Area.java com.inktomi.cirrus.forecast.Categories.java com.inktomi.cirrus.forecast.Category.java com.inktomi.cirrus.forecast.Circle.java com.inktomi.cirrus.forecast.City.java com.inktomi.cirrus.forecast.ConciseName.java com.inktomi.cirrus.forecast.CreationDate.java com.inktomi.cirrus.forecast.DataSource.java com.inktomi.cirrus.forecast.Data.java com.inktomi.cirrus.forecast.Datum.java com.inktomi.cirrus.forecast.DecimalVal.java com.inktomi.cirrus.forecast.Error.java com.inktomi.cirrus.forecast.Field.java com.inktomi.cirrus.forecast.Head.java com.inktomi.cirrus.forecast.HeightUnits.java com.inktomi.cirrus.forecast.Height.java com.inktomi.cirrus.forecast.Icon.java com.inktomi.cirrus.forecast.Layer.java com.inktomi.cirrus.forecast.Level.java com.inktomi.cirrus.forecast.LikelihoodUnits.java com.inktomi.cirrus.forecast.Location.java com.inktomi.cirrus.forecast.MoreWeatherInformation.java com.inktomi.cirrus.forecast.NwsZone.java com.inktomi.cirrus.forecast.OperationalMode.java com.inktomi.cirrus.forecast.Parameters.java com.inktomi.cirrus.forecast.PercentageValue.java com.inktomi.cirrus.forecast.Point.java com.inktomi.cirrus.forecast.Probability.java com.inktomi.cirrus.forecast.Product.java com.inktomi.cirrus.forecast.ProductionCenter.java com.inktomi.cirrus.forecast.Radius.java com.inktomi.cirrus.forecast.Rectangle.java com.inktomi.cirrus.forecast.Source.java com.inktomi.cirrus.forecast.SrsName.java com.inktomi.cirrus.forecast.StartValidTime.java com.inktomi.cirrus.forecast.TemperatureValue.java com.inktomi.cirrus.forecast.TimeCoordinate.java com.inktomi.cirrus.forecast.TimeLayout.java com.inktomi.cirrus.forecast.Uncertainty.java com.inktomi.cirrus.forecast.ValueForRange.java com.inktomi.cirrus.forecast.ValueList.java com.inktomi.cirrus.forecast.WeatherResponse.java com.inktomi.cirrus.forecast.WindDirectionValue.java com.inktomi.cirrus.forecast.WindspeedValue.java