ERemoteOperation.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. package epson.print.copy.Component.eremoteoperation;
  2. import android.util.Log;
  3. import com.epson.iprint.prtlogger.Analytics;
  4. import com.epson.mobilephone.common.wifidirect.ActivityControlWiFi;
  5. import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
  6. import epson.common.IPAddressUtils;
  7. import epson.common.httpclient.BasicNameValuePair;
  8. import epson.common.httpclient.IAHttpClient;
  9. import epson.print.CommonDefine;
  10. import java.io.ByteArrayOutputStream;
  11. import java.io.UnsupportedEncodingException;
  12. import java.util.ArrayList;
  13. import java.util.Arrays;
  14. import java.util.HashMap;
  15. import java.util.Iterator;
  16. import java.util.List;
  17. import org.apache.commons.lang.CharEncoding;
  18. import org.json.JSONObject;
  19. public class ERemoteOperation {
  20. String hostIP;
  21. int requestConnectionTimeout = ActivityControlWiFi.SCANNING_TIMEOUT;
  22. public interface IRemoteOperationParameter {
  23. String client_id();
  24. }
  25. public interface IRemoteStatusParameter extends IRemoteOperationParameter {
  26. ArrayList<ERemoteParam> keys();
  27. }
  28. public void setHostIP(String str) {
  29. this.hostIP = new String(str);
  30. }
  31. public String getHostIP() {
  32. return this.hostIP;
  33. }
  34. public void setRequestConnectionTimeout(int i) {
  35. this.requestConnectionTimeout = i;
  36. }
  37. public int getRequestConnectionTimeout() {
  38. return this.requestConnectionTimeout;
  39. }
  40. public enum ERemoteParam {
  41. client_id("client-id"),
  42. success("success"),
  43. reason("reason"),
  44. illegal_combination("illegal_combination"),
  45. illegal_state("illegal_state"),
  46. already_finished("already_finished"),
  47. unknown_token("unknown_token"),
  48. busy("busy"),
  49. job_token("job-token"),
  50. next_document("next-document"),
  51. functions("functions"),
  52. keys("keys"),
  53. device("device"),
  54. printer(WiFiDirectManager.DEVICE_TYPE_PRINTER),
  55. scanner(WiFiDirectManager.DEVICE_TYPE_SCANNER),
  56. copy("copy"),
  57. copy_photo("copy_photo"),
  58. repeat_copy("repeat_copy"),
  59. print_x_disc_tray_state("print-x-disc-tray-state"),
  60. media_empty("media-empty"),
  61. tray_set("tray-set"),
  62. tray_missing("tray-missing"),
  63. printer_state("printer-state"),
  64. scanner_state("scanner-state"),
  65. idle("idle"),
  66. processing("processing"),
  67. stopped("stopped"),
  68. printer_state_reasons("printer-state-reasons"),
  69. none("none"),
  70. marker_supply_empty_error("marker-supply-empty-error"),
  71. marker_waste_full_error("marker-waste-full-error"),
  72. media_jam_error("media-jam-error"),
  73. media_empty_error("media-empty-error"),
  74. input_tray_missing_error("input-tray-missing-error"),
  75. cover_open_error("cover-open-error"),
  76. output_area_full_error("output-area-full-error"),
  77. other_error("other-error"),
  78. marker_supply_low_warning("marker-supply-low-warning"),
  79. cover_open("cover-open"),
  80. scanner_state_reasons("scanner-state-reasons"),
  81. media_size_missmatch_error("media-size-missmatch-error"),
  82. document_on_adf("document-on-adf"),
  83. components("components"),
  84. disc_tray("disc-tray"),
  85. adf("adf"),
  86. layout("layout"),
  87. standard("standard"),
  88. borderless("borderless"),
  89. two_up("2-up"),
  90. two_up_book("2-up-book"),
  91. book_two_sided("book-two-sided"),
  92. mirror("mirror"),
  93. upper_half("upper-half"),
  94. lower_half("lower_half"),
  95. _3_up("3-up"),
  96. _4_up("4-up"),
  97. _9_up("9-up"),
  98. _16_up("16-up"),
  99. scan_sides("scan-sides"),
  100. print_sides("print-sides"),
  101. one_sided("one-sided"),
  102. two_sided_short_edge("two-sided-short-edge"),
  103. two_sided_long_edge("two-sided-long-edge"),
  104. x_two_sided("x-two-sided"),
  105. scan_media_size("scan-media-size"),
  106. unused("unused"),
  107. iso_a4_210x297mm("iso_a4_210x297mm"),
  108. jis_b4_257x364mm("jis_b4_257x364mm"),
  109. jis_b5_182x257mm("jis_b5_182x257mm"),
  110. print_media_type("print-media-type"),
  111. stationery("stationery"),
  112. photographic_high_gloss("photographic-high-gloss"),
  113. photographic("photographic"),
  114. photographic_semi_gloss("photographic-semi-gloss"),
  115. photographic_glossy("photographic-glossy"),
  116. custom_media_type_epson_44("custom-media-type-epson-44"),
  117. photographic_matte("photographic-matte"),
  118. stationery_coated("stationery-coated"),
  119. custom_media_type_epson_2a("custom-media-type-epson-2a"),
  120. stationery_inkjet("stationery-inkjet"),
  121. custom_media_type_epson_1b("custom-media-type-epson-1b"),
  122. custom_media_type_epson_02("custom-media-type-epson-02"),
  123. custom_media_type_epson_19("custom-media-type-epson-19"),
  124. custom_media_type_epson_22("custom-media-type_epson-22"),
  125. labels("labels"),
  126. envelope("envelope"),
  127. custom_media_type_epson_47("custom-media-type-epson-47"),
  128. custom_media_type_epson_20("custom-media-type-epson-20"),
  129. custom_media_type_epson_39("custom-media-type-epson-39"),
  130. custom_media_type_epson_46("custom-media-type-epson-46"),
  131. stationery_heavyweight("stationery-heavyweight"),
  132. stationery_letterhead("stationery-letterhead"),
  133. print_media_size("print-media-size"),
  134. oe_photo_l_3_5x5in("oe_photo-l_3.5x5in"),
  135. na_5x7_5x7in("na_5x7_5x7in"),
  136. jpn_hagaki_100x148mm("jpn_hagaki_100x148mm"),
  137. na_index_4x6_4x6in("na_index-4x6_4x6in"),
  138. na_govt_letter_8x10in("na_govt-letter_8x10in"),
  139. na_letter_8_5x11in("na_letter_8.5x11in"),
  140. na_legal_8_5x14in("na_legal_8.5x14in"),
  141. iso_a5_148x210mm("iso_a5_148x210mm"),
  142. custom_4psize_254x305mm("custom_4psize_254x305mm"),
  143. iso_a3_297x420mm("iso_a3_297x420mm"),
  144. na_ledger_11x17in("na_ledger_11x17in"),
  145. iso_a6_105x148mm("iso_a6_105x148mm"),
  146. jpn_chou3_120x235mm("jpn_chou3_120x235mm"),
  147. jpn_chou4_90x205mm("jpn_chou4_90x205mm"),
  148. custom_epson_18_120x176mm("custom_epson-18_120x176mm"),
  149. custom_epson_1A_98x148mm("custom_epson-1A_98x148mm"),
  150. jpn_you4_105x235mm("jpn_you4_105x235mm"),
  151. iso_c6_114x162mm("iso_c6_114x162mm"),
  152. jpn_kaku2_240x332mm("jpn_kaku2_240x332mm"),
  153. iso_c4_229x324mm("iso_c4_229x324mm"),
  154. custom_cardsize_55x91mm("custom_cardsize_55x91mm"),
  155. custom_creditcardsize_54x86mm("custom_creditcardsize_54x86mm"),
  156. custom_hivision_101_6x180_6mm("custom_hivision_101.6x180.6mm"),
  157. iso_dl_110x220mm("iso_dl_110x220mm"),
  158. jis_b6_128x182mm("jis_b6_128x182mm"),
  159. na_executive_7_25x10_5in("na_executive_7.25x10.5in"),
  160. na_foolscap_8_5x13in("na_foolscap_8.5x13in"),
  161. na_edp_11x14in("na_edp_11x14in"),
  162. na_number_10_4_125x9_5in("na_number-10_4.125x9.5in"),
  163. om_8k_270x390mm("om_8k_270x390mm"),
  164. om_16k_195x270mm("om_16k_195x270mm"),
  165. na_invoice_5_5x8_5in("na_invoice_5.5x8.5in"),
  166. custom_epson_indianlegal_215x345mm("custom_epson-indianlegal_215x345mm"),
  167. na_oficio_8_5x13_4in("na_oficio_8.5x13.4in"),
  168. om_folio_sp_215x315mm("om_folio-sp_215x315mm"),
  169. scan_content_type("scan-content-type"),
  170. text("text"),
  171. mixed("mixed"),
  172. print_media_source("print-media-source"),
  173. top("top"),
  174. bottom("bottom"),
  175. manual("manual"),
  176. rear("rear"),
  177. print_quality("print-quality"),
  178. draft("draft"),
  179. normal("normal"),
  180. high("high"),
  181. best("x-best"),
  182. print_sheet_collate("print-sheet-collate"),
  183. collated("collated"),
  184. uncollated("uncollated"),
  185. fixed_parameters("fixed-parameters"),
  186. preferred_parameters("preferred-parameters"),
  187. priority_order("priority-order"),
  188. default_as_fixed("default-as-fixed"),
  189. frame("frame"),
  190. oval("oval"),
  191. oval_soft_edge("oval-soft-edge"),
  192. copies("copies"),
  193. color_effects_type("color-effects-type"),
  194. color("color"),
  195. monochrome_grayscale("monochrome-grayscale"),
  196. copy_magnification("copy-magnification"),
  197. auto("auto"),
  198. x_density("x-density"),
  199. print_x_bleed("print-x-bleed"),
  200. midium("midium"),
  201. minimum("minimum"),
  202. orientation("orientation"),
  203. portrait("portrait"),
  204. landscape("landscape"),
  205. print_x_dry_time("print-x-dry-time"),
  206. Long("long"),
  207. longer("longer"),
  208. print_x_auto_pg("print-x-auto-pg"),
  209. on("on"),
  210. off("off"),
  211. job_state("job-state"),
  212. nextpaper("nextpaper"),
  213. scanning("scanning"),
  214. printing("printing"),
  215. copying("copying"),
  216. canceling("canceling"),
  217. finished("finished"),
  218. pending("pending"),
  219. pending_for_template("pending-for-template"),
  220. waiting_image_for_template("waiting-image-for-template"),
  221. printing_template("printing-template"),
  222. waiting_image("waiting-image"),
  223. waiting_template("waiting-template"),
  224. job_result("job-result"),
  225. canceled("canceled"),
  226. memory_full("memory_full"),
  227. remove_adf_paper("remove_adf_paper"),
  228. set_adf_paper("set_adf_paper"),
  229. document_error("document_error"),
  230. image_too_large("image-too-large"),
  231. communication_error("communication-error"),
  232. job_tokens("job-tokens"),
  233. job_print_total_pages("job-print-total-pages"),
  234. job_print_current_pages("job-print-current-pages"),
  235. job_image_post_url("job-image-post-url"),
  236. x_apf("x-apf"),
  237. x_color_restoration("x-color-restoration"),
  238. scan_count("scan-count"),
  239. scan_area_x("scan-area-x"),
  240. scan_area_y("scan-area-y"),
  241. scan_area_width("scan-area-width"),
  242. scan_area_height("scan-area-height"),
  243. scan_area_resolution("scan-area-resolution"),
  244. x_fit_gamma("x-fit-gamma"),
  245. x_fit_matrix("x-fit-matrix"),
  246. x_scale("x-scale"),
  247. x_scale_fullsize("x-scale-fullsize"),
  248. x_scale_custom("x-scale-custom"),
  249. x_scale_autofit("x-scale-autofit"),
  250. x_scale_a4_to_postcard("x-scale-a4-to-postcard"),
  251. x_scale_2l_to_postcard("x-scale-2l-to-postcard"),
  252. x_scale_l_to_postcard("x-scale-l-to-postcard"),
  253. x_scale_l_to_2l("x-scale-l-to-2l"),
  254. x_scale_2l_to_a4("x-scale-2l-to-a4"),
  255. x_scale_postcard_to_a4("x-scale-postcard-to-a4"),
  256. x_scale_l_to_a4("x-scale-l-to-a4"),
  257. x_scale_a4_to_b5("x-scale-a4-to-b5"),
  258. x_scale_b5_to_a4("x-scale-b5-to-a4"),
  259. x_scale_letter_to_kg("x-scale-letter-to-kg"),
  260. x_scale_kg_to_letter("x-scale-kg-to-letter"),
  261. x_scale_letter_to_2l("x-scale-letter-to-2l"),
  262. x_scale_2l_to_letter("x-scale-2l-to-letter"),
  263. x_scale_kg_to_a4("x-scale-kg-to-a4"),
  264. x_scale_a4_to_kg("x-scale-a4-to-kg"),
  265. x_scale_a4_to_2l("x-scale-a4-to-2l"),
  266. x_scale_kg_to_8x10("x-scale-kg-to-8x10"),
  267. x_scale_8x10_to_2l("x-scale-8x10-to-2l"),
  268. x_scale_legal_to_letter("x-scale-legal-to-letter"),
  269. x_scale_2l_to_kg("x-scale-2l-to-kg"),
  270. x_scale_kg_to_2l("x-scale-kg-to-2l"),
  271. x_scale_a5_to_a4("x-scale-a5-to-a4"),
  272. x_scale_a4_to_a5("x-scale-a4-to-a5"),
  273. x_scale_a4_to_a3("x-scale-a4-to-a3"),
  274. x_scale_letter_to_11x17("x-scale-letter-to-11x17"),
  275. x_borderless("layout"),
  276. x_null(""),
  277. x_failed_communication("x-failed-communication"),
  278. x_unknown("x-unknown"),
  279. x_invalid_photo_setting("x-invalid-photo-setting");
  280. public String string;
  281. private ERemoteParam(String str) {
  282. this.string = str;
  283. }
  284. public static ERemoteParam stringOf(String str) {
  285. for (ERemoteParam eRemoteParam : values()) {
  286. if (eRemoteParam.string.compareTo(str) == 0) {
  287. return eRemoteParam;
  288. }
  289. }
  290. return x_null;
  291. }
  292. public String toString() {
  293. return this.string;
  294. }
  295. }
  296. enum RequestParam {
  297. remote_operation("remote_operation"),
  298. v1("v1"),
  299. HTTP(Analytics.EXTENSION_STRING_WEB),
  300. Content_Type("application/x-www-form-urlencoded"),
  301. User_Agent("Mozilla/5.0"),
  302. device("device"),
  303. printer(WiFiDirectManager.DEVICE_TYPE_PRINTER),
  304. scanner(WiFiDirectManager.DEVICE_TYPE_SCANNER),
  305. copy("copy"),
  306. copy_photo("copy_photo"),
  307. combo("combo"),
  308. get_functions("get_functions"),
  309. get_status("get_status"),
  310. get_components("get_components"),
  311. get_options("get_options"),
  312. clear_error("clear_error"),
  313. cancel("cancel"),
  314. document_changed("document_changed");
  315. public String string;
  316. private RequestParam(String str) {
  317. this.string = str;
  318. }
  319. }
  320. public static class ERemoteOperationResult {
  321. JSONObject json;
  322. ERemoteRequestBuilder request;
  323. static JSONObject parseResponse(IAHttpClient.HttpResponse httpResponse) {
  324. JSONObject jSONObject = new JSONObject();
  325. try {
  326. ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  327. httpResponse.getEntity().writeTo(byteArrayOutputStream);
  328. Log.d("ERequest C", byteArrayOutputStream.toString());
  329. return new JSONObject(byteArrayOutputStream.toString());
  330. } catch (Exception e) {
  331. e.printStackTrace();
  332. return jSONObject;
  333. }
  334. }
  335. public ERemoteOperationResult(JSONObject jSONObject) {
  336. this.json = jSONObject;
  337. }
  338. public String toString() {
  339. return this.json.toString();
  340. }
  341. public boolean isNull(ERemoteParam eRemoteParam) {
  342. return this.json.isNull(eRemoteParam.string);
  343. }
  344. public void setRemoteRequestBuilder(ERemoteRequestBuilder eRemoteRequestBuilder) {
  345. this.request = eRemoteRequestBuilder;
  346. }
  347. public boolean success() {
  348. try {
  349. return this.json.getBoolean(ERemoteParam.success.string);
  350. } catch (Exception e) {
  351. e.printStackTrace();
  352. return false;
  353. }
  354. }
  355. private boolean getBooleanValueOf(ERemoteParam eRemoteParam) {
  356. try {
  357. return this.json.getBoolean(eRemoteParam.string);
  358. } catch (Exception e) {
  359. e.printStackTrace();
  360. return false;
  361. }
  362. }
  363. private int getIntValueOf(ERemoteParam eRemoteParam) {
  364. try {
  365. return this.json.getInt(eRemoteParam.string);
  366. } catch (Exception e) {
  367. e.printStackTrace();
  368. return 0;
  369. }
  370. }
  371. private String getStringValueOf(ERemoteParam eRemoteParam) {
  372. try {
  373. return this.json.getString(eRemoteParam.string);
  374. } catch (Exception e) {
  375. e.printStackTrace();
  376. return "";
  377. }
  378. }
  379. private ArrayList<String> getStringsValueOf(ERemoteParam eRemoteParam) {
  380. ArrayList<String> arrayList = new ArrayList<>();
  381. try {
  382. for (String trim : this.json.getString(eRemoteParam.string).split(PreferencesConstants.COOKIE_DELIMITER)) {
  383. arrayList.add(trim.trim());
  384. }
  385. } catch (Exception e) {
  386. e.printStackTrace();
  387. }
  388. return arrayList;
  389. }
  390. private ERemoteParam getParamValueOf(ERemoteParam eRemoteParam) {
  391. ERemoteParam eRemoteParam2 = ERemoteParam.x_null;
  392. try {
  393. return ERemoteParam.stringOf(this.json.getString(eRemoteParam.string));
  394. } catch (Exception e) {
  395. e.printStackTrace();
  396. return eRemoteParam2;
  397. }
  398. }
  399. private ERemoteParam getDefaultValueOf(ERemoteParam eRemoteParam) {
  400. ERemoteParam eRemoteParam2 = ERemoteParam.x_null;
  401. try {
  402. JSONObject jSONObject = this.json;
  403. return ERemoteParam.stringOf(jSONObject.getString(eRemoteParam.string + "-default"));
  404. } catch (Exception e) {
  405. e.printStackTrace();
  406. return eRemoteParam2;
  407. }
  408. }
  409. private ArrayList<ERemoteParam> getOptionsValueOf(ERemoteParam eRemoteParam) {
  410. ArrayList<ERemoteParam> arrayList = new ArrayList<>();
  411. try {
  412. for (String trim : this.json.getString(eRemoteParam.string + "-options").split(PreferencesConstants.COOKIE_DELIMITER)) {
  413. ERemoteParam stringOf = ERemoteParam.stringOf(trim.trim());
  414. if (stringOf != ERemoteParam.x_null) {
  415. arrayList.add(stringOf);
  416. }
  417. }
  418. } catch (Exception e) {
  419. e.printStackTrace();
  420. }
  421. return arrayList;
  422. }
  423. private ArrayList<ERemoteParam> getParamsValueOf(ERemoteParam eRemoteParam) {
  424. ArrayList<ERemoteParam> arrayList = new ArrayList<>();
  425. try {
  426. for (String trim : getStringValueOf(eRemoteParam).split(PreferencesConstants.COOKIE_DELIMITER)) {
  427. arrayList.add(ERemoteParam.stringOf(trim.trim()));
  428. }
  429. } catch (Exception e) {
  430. e.printStackTrace();
  431. }
  432. return arrayList;
  433. }
  434. }
  435. public class ERemoteReasonResult extends ERemoteOperationResult {
  436. public ERemoteReasonResult(JSONObject jSONObject) {
  437. super(jSONObject);
  438. }
  439. public ERemoteParam reason() {
  440. return getParamValueOf(ERemoteParam.reason);
  441. }
  442. }
  443. class ERemoteRequest {
  444. IAHttpClient.HttpPost request;
  445. int timeout;
  446. public ERemoteRequest(String str, ArrayList<BasicNameValuePair> arrayList, int i) {
  447. try {
  448. this.request = new IAHttpClient.HttpPost(str);
  449. this.request.setContentEncoding(CharEncoding.UTF_8);
  450. this.request.setContentType(RequestParam.Content_Type.string);
  451. this.request.setEntity(IAHttpClient.HttpPost.getUrlEncodedFormEntity(arrayList, CharEncoding.UTF_8));
  452. this.timeout = i;
  453. } catch (UnsupportedEncodingException e) {
  454. e.printStackTrace();
  455. }
  456. }
  457. public JSONObject execute() {
  458. try {
  459. Log.d("ERequest A", this.request.getURI().toString());
  460. ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  461. this.request.getEntity().writeTo(byteArrayOutputStream);
  462. Log.d("ERequest B", byteArrayOutputStream.toString());
  463. IAHttpClient iAHttpClient = new IAHttpClient();
  464. iAHttpClient.setConnectionTimeout(this.timeout);
  465. iAHttpClient.setSoTimeout(this.timeout);
  466. return ERemoteOperationResult.parseResponse(iAHttpClient.execute(this.request));
  467. } catch (Exception e) {
  468. e.printStackTrace();
  469. return new JSONObject();
  470. }
  471. }
  472. }
  473. static class ERemoteRequestBuilder extends ERemoteOperation {
  474. RequestParam command;
  475. ArrayList<BasicNameValuePair> messageBody = new ArrayList<>();
  476. RequestParam operation;
  477. HashMap<ERemoteParam, Object> remoteParam;
  478. StringBuffer requestURI;
  479. int timeout;
  480. RequestParam version;
  481. public interface VariantValueConverter {
  482. ERemoteParam convertValue(int i);
  483. }
  484. ERemoteRequestBuilder(String str, RequestParam requestParam, RequestParam requestParam2, RequestParam requestParam3, int i) {
  485. this.operation = requestParam;
  486. this.version = requestParam2;
  487. this.command = requestParam3;
  488. this.timeout = i;
  489. StringBuffer stringBuffer = new StringBuffer();
  490. stringBuffer.append(CommonDefine.SLASH);
  491. stringBuffer.append(RequestParam.remote_operation.string);
  492. stringBuffer.append(CommonDefine.SLASH);
  493. stringBuffer.append(requestParam2.string);
  494. stringBuffer.append(CommonDefine.SLASH);
  495. stringBuffer.append(requestParam.string);
  496. stringBuffer.append(CommonDefine.SLASH);
  497. stringBuffer.append(requestParam3.string);
  498. this.requestURI = new StringBuffer(IPAddressUtils.buildURL(RequestParam.HTTP.string, str, stringBuffer.toString()));
  499. this.remoteParam = new HashMap<>();
  500. }
  501. private void deleteLastCharIf(StringBuffer stringBuffer, char c) {
  502. if (stringBuffer.length() > 0) {
  503. int length = stringBuffer.length() - 1;
  504. if (stringBuffer.charAt(length) == c) {
  505. stringBuffer.deleteCharAt(length);
  506. }
  507. }
  508. }
  509. public static ERemoteRequestBuilder requestDevice(String str, RequestParam requestParam, int i) {
  510. return new ERemoteRequestBuilder(str, RequestParam.device, RequestParam.v1, requestParam, i);
  511. }
  512. public static ERemoteRequestBuilder requestPrinter(String str, RequestParam requestParam, int i) {
  513. return new ERemoteRequestBuilder(str, RequestParam.printer, RequestParam.v1, requestParam, i);
  514. }
  515. public static ERemoteRequestBuilder requestScanner(String str, RequestParam requestParam, int i) {
  516. return new ERemoteRequestBuilder(str, RequestParam.scanner, RequestParam.v1, requestParam, i);
  517. }
  518. public static ERemoteRequestBuilder requestCopy(String str, RequestParam requestParam, int i) {
  519. return new ERemoteRequestBuilder(str, RequestParam.copy, RequestParam.v1, requestParam, i);
  520. }
  521. public static ERemoteRequestBuilder requestCopyPhoto(String str, RequestParam requestParam, int i) {
  522. return new ERemoteRequestBuilder(str, RequestParam.copy_photo, RequestParam.v1, requestParam, i);
  523. }
  524. public static ERemoteRequestBuilder requestCombo(String str, RequestParam requestParam, int i) {
  525. return new ERemoteRequestBuilder(str, RequestParam.combo, RequestParam.v1, requestParam, i);
  526. }
  527. public void add(ERemoteParam eRemoteParam, boolean z) {
  528. this.remoteParam.put(eRemoteParam, new Boolean(z));
  529. this.messageBody.add(new BasicNameValuePair(eRemoteParam.string, String.valueOf(z)));
  530. }
  531. public void add(ERemoteParam eRemoteParam, int i) {
  532. this.remoteParam.put(eRemoteParam, new Integer(i));
  533. this.messageBody.add(new BasicNameValuePair(eRemoteParam.string, String.valueOf(i)));
  534. }
  535. public void add(ERemoteParam eRemoteParam, int[] iArr) {
  536. this.remoteParam.put(eRemoteParam, Arrays.asList(new int[][]{iArr}));
  537. StringBuffer stringBuffer = new StringBuffer();
  538. for (int append : iArr) {
  539. stringBuffer.append(append);
  540. stringBuffer.append(PreferencesConstants.COOKIE_DELIMITER);
  541. }
  542. deleteLastCharIf(stringBuffer, ',');
  543. this.messageBody.add(new BasicNameValuePair(eRemoteParam.string, String.valueOf(stringBuffer)));
  544. }
  545. public void add(ERemoteParam eRemoteParam, String str) {
  546. if (!str.equals(ERemoteParam.x_null.string)) {
  547. this.remoteParam.put(eRemoteParam, str);
  548. this.messageBody.add(new BasicNameValuePair(eRemoteParam.string, str));
  549. }
  550. }
  551. public void add(ERemoteParam eRemoteParam, int i, VariantValueConverter variantValueConverter) {
  552. String valueOf = String.valueOf(i);
  553. ERemoteParam convertValue = variantValueConverter.convertValue(i);
  554. if (convertValue != null) {
  555. valueOf = convertValue.string;
  556. }
  557. this.remoteParam.put(eRemoteParam, valueOf);
  558. this.messageBody.add(new BasicNameValuePair(eRemoteParam.string, valueOf));
  559. }
  560. public void add(ERemoteParam eRemoteParam, ERemoteParam eRemoteParam2) {
  561. if (eRemoteParam2 != ERemoteParam.x_null) {
  562. this.remoteParam.put(eRemoteParam, eRemoteParam2);
  563. this.messageBody.add(new BasicNameValuePair(eRemoteParam.string, eRemoteParam2.string));
  564. }
  565. }
  566. public void add(ERemoteParam eRemoteParam, ArrayList<ERemoteParam> arrayList) {
  567. this.remoteParam.put(eRemoteParam, arrayList);
  568. StringBuffer stringBuffer = new StringBuffer();
  569. Iterator<ERemoteParam> it = arrayList.iterator();
  570. while (it.hasNext()) {
  571. stringBuffer.append(it.next().string);
  572. stringBuffer.append(PreferencesConstants.COOKIE_DELIMITER);
  573. }
  574. deleteLastCharIf(stringBuffer, ',');
  575. this.messageBody.add(new BasicNameValuePair(eRemoteParam.string, String.valueOf(stringBuffer)));
  576. }
  577. public void add(ERemoteParam eRemoteParam, List<String> list) {
  578. this.remoteParam.put(eRemoteParam, list);
  579. StringBuffer stringBuffer = new StringBuffer();
  580. for (String append : list) {
  581. stringBuffer.append(append);
  582. stringBuffer.append(PreferencesConstants.COOKIE_DELIMITER);
  583. }
  584. deleteLastCharIf(stringBuffer, ',');
  585. this.messageBody.add(new BasicNameValuePair(eRemoteParam.string, String.valueOf(stringBuffer)));
  586. }
  587. public ERemoteRequest getRemoteRequest() {
  588. return new ERemoteRequest(this.requestURI.toString(), this.messageBody, this.timeout);
  589. }
  590. }
  591. }