00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 package org.xbmc.android.jsonrpc.api.call;
00022
00023 import android.os.Parcel;
00024 import android.os.Parcelable;
00025 import java.util.ArrayList;
00026 import java.util.Arrays;
00027 import java.util.HashSet;
00028 import java.util.List;
00029 import java.util.Set;
00030 import org.codehaus.jackson.JsonNode;
00031 import org.codehaus.jackson.node.ArrayNode;
00032 import org.codehaus.jackson.node.ObjectNode;
00033 import org.xbmc.android.jsonrpc.api.AbstractCall;
00034 import org.xbmc.android.jsonrpc.api.AbstractModel;
00035 import org.xbmc.android.jsonrpc.api.model.ListModel;
00036
00037 public final class Files {
00038
00046 public static class GetDirectory extends AbstractCall<ListModel.FileItem> {
00047 public final static String API_TYPE = "Files.GetDirectory";
00048
00049 @Override
00050 public void writeToParcel(Parcel parcel, int flags) {
00051 super.writeToParcel(parcel, flags);
00052 parcel.writeParcelable(mResult, flags);
00053 }
00054
00058 protected GetDirectory(Parcel parcel) {
00059 super(parcel);
00060 }
00061
00065 public static final Parcelable.Creator<GetDirectory> CREATOR = new Parcelable.Creator<GetDirectory>() {
00066 @Override
00067 public GetDirectory createFromParcel(Parcel parcel) {
00068 return new GetDirectory(parcel);
00069 }
00070 @Override
00071 public GetDirectory[] newArray(int n) {
00072 return new GetDirectory[n];
00073 }
00074 };
00075 public final static String RESULT = "files";
00076
00085 public GetDirectory(String directory, String media, ListModel.Sort sort, ListModel.Limits limits, String... properties) {
00086 super();
00087 addParameter("directory", directory);
00088 addParameter("media", media);
00089 addParameter("sort", sort);
00090 addParameter("limits", limits);
00091 addParameter("properties", properties);
00092 }
00093
00099 public GetDirectory(String directory, String... properties) {
00100 super();
00101 addParameter("directory", directory);
00102 addParameter("properties", properties);
00103 }
00104
00111 public GetDirectory(String directory, String media, String... properties) {
00112 super();
00113 addParameter("directory", directory);
00114 addParameter("media", media);
00115 addParameter("properties", properties);
00116 }
00117
00124 public GetDirectory(String directory, ListModel.Sort sort, String... properties) {
00125 super();
00126 addParameter("directory", directory);
00127 addParameter("sort", sort);
00128 addParameter("properties", properties);
00129 }
00130
00138 public GetDirectory(String directory, String media, ListModel.Sort sort, String... properties) {
00139 super();
00140 addParameter("directory", directory);
00141 addParameter("media", media);
00142 addParameter("sort", sort);
00143 addParameter("properties", properties);
00144 }
00145
00152 public GetDirectory(String directory, ListModel.Limits limits, String... properties) {
00153 super();
00154 addParameter("directory", directory);
00155 addParameter("limits", limits);
00156 addParameter("properties", properties);
00157 }
00158
00166 public GetDirectory(String directory, ListModel.Sort sort, ListModel.Limits limits, String... properties) {
00167 super();
00168 addParameter("directory", directory);
00169 addParameter("sort", sort);
00170 addParameter("limits", limits);
00171 addParameter("properties", properties);
00172 }
00173
00174 @Override
00175 protected ArrayList<ListModel.FileItem> parseMany(JsonNode node) {
00176 final ArrayNode files = parseResults(node, RESULT);
00177 if (files != null) {
00178 final ArrayList<ListModel.FileItem> ret = new ArrayList<ListModel.FileItem>(files.size());
00179 for (int i = 0; i < files.size(); i++) {
00180 final ObjectNode item = (ObjectNode)files.get(i);
00181 ret.add(new ListModel.FileItem(item));
00182 }
00183 return ret;
00184 } else {
00185 return new ArrayList<ListModel.FileItem>(0);
00186 }
00187 }
00188
00189 @Override
00190 public String getName() {
00191 return API_TYPE;
00192 }
00193
00194 @Override
00195 protected boolean returnsList() {
00196 return true;
00197 }
00198 }
00199
00207 public static class GetFileDetails extends AbstractCall<ListModel.FileItem> {
00208 public final static String API_TYPE = "Files.GetFileDetails";
00209
00210 @Override
00211 public void writeToParcel(Parcel parcel, int flags) {
00212 super.writeToParcel(parcel, flags);
00213 parcel.writeParcelable(mResult, flags);
00214 }
00215
00219 protected GetFileDetails(Parcel parcel) {
00220 super(parcel);
00221 }
00222
00226 public static final Parcelable.Creator<GetFileDetails> CREATOR = new Parcelable.Creator<GetFileDetails>() {
00227 @Override
00228 public GetFileDetails createFromParcel(Parcel parcel) {
00229 return new GetFileDetails(parcel);
00230 }
00231 @Override
00232 public GetFileDetails[] newArray(int n) {
00233 return new GetFileDetails[n];
00234 }
00235 };
00236 public final static String RESULT = "filedetails";
00237
00244 public GetFileDetails(String file, String media, String... properties) {
00245 super();
00246 addParameter("file", file);
00247 addParameter("media", media);
00248 addParameter("properties", properties);
00249 }
00250
00256 public GetFileDetails(String file, String... properties) {
00257 super();
00258 addParameter("file", file);
00259 addParameter("properties", properties);
00260 }
00261
00262 @Override
00263 protected ListModel.FileItem parseOne(JsonNode node) {
00264 return new ListModel.FileItem((ObjectNode)node.get(RESULT));
00265 }
00266
00267 @Override
00268 public String getName() {
00269 return API_TYPE;
00270 }
00271
00272 @Override
00273 protected boolean returnsList() {
00274 return false;
00275 }
00276 }
00277
00285 public static class GetSources extends AbstractCall<ListModel.SourceItem> {
00286 public final static String API_TYPE = "Files.GetSources";
00287
00288 @Override
00289 public void writeToParcel(Parcel parcel, int flags) {
00290 super.writeToParcel(parcel, flags);
00291 parcel.writeParcelable(mResult, flags);
00292 }
00293
00297 protected GetSources(Parcel parcel) {
00298 super(parcel);
00299 }
00300
00304 public static final Parcelable.Creator<GetSources> CREATOR = new Parcelable.Creator<GetSources>() {
00305 @Override
00306 public GetSources createFromParcel(Parcel parcel) {
00307 return new GetSources(parcel);
00308 }
00309 @Override
00310 public GetSources[] newArray(int n) {
00311 return new GetSources[n];
00312 }
00313 };
00314 public final static String RESULT = "sources";
00315
00322 public GetSources(String media, ListModel.Limits limits, ListModel.Sort sort) {
00323 super();
00324 addParameter("media", media);
00325 addParameter("limits", limits);
00326 addParameter("sort", sort);
00327 }
00328
00333 public GetSources(String media) {
00334 super();
00335 addParameter("media", media);
00336 }
00337
00343 public GetSources(String media, ListModel.Limits limits) {
00344 super();
00345 addParameter("media", media);
00346 addParameter("limits", limits);
00347 }
00348
00349 @Override
00350 protected ArrayList<ListModel.SourceItem> parseMany(JsonNode node) {
00351 final ArrayNode sources = parseResults(node, RESULT);
00352 if (sources != null) {
00353 final ArrayList<ListModel.SourceItem> ret = new ArrayList<ListModel.SourceItem>(sources.size());
00354 for (int i = 0; i < sources.size(); i++) {
00355 final ObjectNode item = (ObjectNode)sources.get(i);
00356 ret.add(new ListModel.SourceItem(item));
00357 }
00358 return ret;
00359 } else {
00360 return new ArrayList<ListModel.SourceItem>(0);
00361 }
00362 }
00363
00364 @Override
00365 public String getName() {
00366 return API_TYPE;
00367 }
00368
00369 @Override
00370 protected boolean returnsList() {
00371 return true;
00372 }
00373 }
00374
00382 public static class PrepareDownload extends AbstractCall<PrepareDownload.PrepareDownloadResult> {
00383 public final static String API_TYPE = "Files.PrepareDownload";
00384
00385 @Override
00386 public void writeToParcel(Parcel parcel, int flags) {
00387 super.writeToParcel(parcel, flags);
00388 parcel.writeParcelable(mResult, flags);
00389 }
00390
00394 protected PrepareDownload(Parcel parcel) {
00395 super(parcel);
00396 }
00397
00401 public static final Parcelable.Creator<PrepareDownload> CREATOR = new Parcelable.Creator<PrepareDownload>() {
00402 @Override
00403 public PrepareDownload createFromParcel(Parcel parcel) {
00404 return new PrepareDownload(parcel);
00405 }
00406 @Override
00407 public PrepareDownload[] newArray(int n) {
00408 return new PrepareDownload[n];
00409 }
00410 };
00411
00416 public PrepareDownload(String path) {
00417 super();
00418 addParameter("path", path);
00419 }
00420
00421 @Override
00422 protected PrepareDownloadResult parseOne(JsonNode node) {
00423 return new PrepareDownloadResult(node);
00424 }
00425
00426 @Override
00427 public String getName() {
00428 return API_TYPE;
00429 }
00430
00431 @Override
00432 protected boolean returnsList() {
00433 return false;
00434 }
00435
00440 public static class PrepareDownloadResult extends AbstractModel {
00441
00442
00443 public static final String DETAILS = "details";
00444 public static final String MODE = "mode";
00445 public static final String PROTOCOL = "protocol";
00446
00447
00448 public final String details;
00449 public final String mode;
00450 public final String protocol;
00451
00457 public PrepareDownloadResult(String details, String mode, String protocol) {
00458 this.details = details;
00459 this.mode = mode;
00460 this.protocol = protocol;
00461 }
00462
00467 public PrepareDownloadResult(JsonNode node) {
00468 details = node.get(DETAILS).getTextValue();
00469 mode = parseString(node, MODE);
00470 protocol = parseString(node, PROTOCOL);
00471 }
00472
00473 @Override
00474 public JsonNode toJsonNode() {
00475 final ObjectNode node = OM.createObjectNode();
00476 node.put(DETAILS, details);
00477 node.put(MODE, mode);
00478 node.put(PROTOCOL, protocol);
00479 return node;
00480 }
00481
00487 static List<PrepareDownloadResult> getFilesPrepareDownloadResultList(JsonNode node, String key) {
00488 if (node.has(key)) {
00489 final ArrayNode a = (ArrayNode)node.get(key);
00490 final List<PrepareDownloadResult> l = new ArrayList<PrepareDownloadResult>(a.size());
00491 for (int i = 0; i < a.size(); i++) {
00492 l.add(new PrepareDownloadResult((JsonNode)a.get(i)));
00493 }
00494 return l;
00495 }
00496 return new ArrayList<PrepareDownloadResult>(0);
00497 }
00498
00504 @Override
00505 public void writeToParcel(Parcel parcel, int flags) {
00506 parcel.writeValue(details);
00507 parcel.writeValue(mode);
00508 parcel.writeValue(protocol);
00509 }
00510
00514 protected PrepareDownloadResult(Parcel parcel) {
00515 details = parcel.readString();
00516 mode = parcel.readString();
00517 protocol = parcel.readString();
00518 }
00519
00523 public static final Parcelable.Creator<PrepareDownloadResult> CREATOR = new Parcelable.Creator<PrepareDownloadResult>() {
00524 @Override
00525 public PrepareDownloadResult createFromParcel(Parcel parcel) {
00526 return new PrepareDownloadResult(parcel);
00527 }
00528 @Override
00529 public PrepareDownloadResult[] newArray(int n) {
00530 return new PrepareDownloadResult[n];
00531 }
00532 };
00533
00534 @Override
00535 public int describeContents() {
00536 return 0;
00537 }
00538
00542 public interface Protocol {
00543
00544 public final String HTTP = "http";
00545
00546 public final static Set<String> values = new HashSet<String>(Arrays.asList(HTTP));
00547 }
00548
00552 public interface Mode {
00553
00554 public final String REDIRECT = "redirect";
00555 public final String DIRECT = "direct";
00556
00557 public final static Set<String> values = new HashSet<String>(Arrays.asList(REDIRECT, DIRECT));
00558 }
00559 }
00560 }
00561 }