Commit cca038b0 authored by josmas's avatar josmas Committed by Gerrit Review System

Adds PUT and DELETE calls to Web component, plus minor changes in internal methods

Change-Id: I74cb511921b222cae57b38783c414587824ac6cf
parent 69ebd508
......@@ -967,6 +967,12 @@ public final class YoungAndroidFormUpgrader {
// No properties need to be modified to upgrade to version 2.
srcCompVersion = 2;
}
if (srcCompVersion < 3) {
// The methods PutText, PutTextWithEncoding, PutFile and Delete were added.
// The method BuildPostData was renamed to BuildRequestData.
// No properties need to be modified to upgrade to version 3.
srcCompVersion = 3;
}
return srcCompVersion;
}
......
......@@ -12,14 +12,13 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
/**
* BlockSaveFile is the saved form of the blocks workspace. This helper class
* reads in the block save file and provides access to its version info.
......@@ -1243,6 +1242,18 @@ public class BlockSaveFile {
// Blocks related to this component have now been upgraded to version 2.
blkCompVersion = 2;
}
if (blkCompVersion < 3) {
// Change BuildPostData function to BuildRequestData.
for (Element block : getAllMatchingMethodOrEventBlocks(componentName,
"Web", "BuildPostData")) {
changeBlockGenusName(block, "Web-BuildRequestData");
Node labelChild = getBlockLabelChild(block);
String newLabel = componentName + ".BuildRequestData";
labelChild.setNodeValue(newLabel);
}
// Blocks related to this component have now been upgraded to version 3.
blkCompVersion = 3;
}
return blkCompVersion;
}
......
......@@ -219,7 +219,9 @@ public class YaVersion {
// - BUTTON_COMPONENT_VERSION was incremented to 5.
// For YOUNG_ANDROID_VERSION 74:
// - SLIDER_COMPONENT_VERSION was incremented to 1.
public static final int YOUNG_ANDROID_VERSION = 74;
// For YOUNG_ANDROID_VERSION 75:
// - WEBVIEWER_COMPONENT_VERSION was incremented to 3
public static final int YOUNG_ANDROID_VERSION = 75;
// ............................... Blocks Language Version Number ...............................
......@@ -603,7 +605,9 @@ public class YaVersion {
// - The BuildPostData and ClearCookies methods were added.
// - The existing PostText method was renamed to PostTextWithEncoding, and a new PostText
// method was added.
public static final int WEB_COMPONENT_VERSION = 2;
// For WEB_COMPONENT_VERSION 3:
// - PUT and DELETE Actions added (PutText, PutTextWithEncoding, PutFile, and Delete).
public static final int WEB_COMPONENT_VERSION = 3;
// For WEBVIEWER_COMPONENT_VERSION 2:
// - The CanGoForward and CanGoBack methods were added
......
......@@ -103,16 +103,17 @@ public final class ErrorMessages {
// Web errors
public static final int ERROR_WEB_UNABLE_TO_GET = 1101;
public static final int ERROR_WEB_UNSUPPORTED_ENCODING = 1102;
public static final int ERROR_WEB_UNABLE_TO_POST = 1103;
public static final int ERROR_WEB_UNABLE_TO_POST_FILE = 1104;
public static final int ERROR_WEB_UNABLE_TO_POST_OR_PUT = 1103;
public static final int ERROR_WEB_UNABLE_TO_POST_OR_PUT_FILE = 1104;
public static final int ERROR_WEB_JSON_TEXT_DECODE_FAILED = 1105;
public static final int ERROR_WEB_HTML_TEXT_DECODE_FAILED = 1106;
// There is a gap here because two ContactPicker errors below use the numbers 1107 and 1108.
public static final int ERROR_WEB_MALFORMED_URL = 1109;
public static final int ERROR_WEB_REQUEST_HEADER_NOT_LIST = 1110;
public static final int ERROR_WEB_REQUEST_HEADER_NOT_TWO_ELEMENTS = 1111;
public static final int ERROR_WEB_BUILD_POST_DATA_NOT_LIST = 1112;
public static final int ERROR_WEB_BUILD_POST_DATA_NOT_TWO_ELEMENTS = 1113;
public static final int ERROR_WEB_BUILD_REQUEST_DATA_NOT_LIST = 1112;
public static final int ERROR_WEB_BUILD_REQUEST_DATA_NOT_TWO_ELEMENTS = 1113;
public static final int ERROR_WEB_UNABLE_TO_DELETE = 1114;
// Contact picker (and PhoneNumberPicker) errors
public static final int ERROR_PHONE_UNSUPPORTED_CONTACT_PICKER = 1107;
public static final int ERROR_PHONE_UNSUPPORTED_SEARCH_IN_CONTACT_PICKING = 1108;
......@@ -306,10 +307,10 @@ public final class ErrorMessages {
"Unable to get a response with the specified URL: %s");
errorMessages.put(ERROR_WEB_UNSUPPORTED_ENCODING,
"The encoding %s is not supported.");
errorMessages.put(ERROR_WEB_UNABLE_TO_POST,
"Unable to post the text \"%s\" with the specified URL: %s");
errorMessages.put(ERROR_WEB_UNABLE_TO_POST_FILE,
"Unable to post the file \"%s\" with the specified URL %s.");
errorMessages.put(ERROR_WEB_UNABLE_TO_POST_OR_PUT,
"Unable to post or put the text \"%s\" with the specified URL: %s");
errorMessages.put(ERROR_WEB_UNABLE_TO_POST_OR_PUT_FILE,
"Unable to post or put the file \"%s\" with the specified URL %s.");
errorMessages.put(ERROR_WEB_JSON_TEXT_DECODE_FAILED,
"Unable to decode the JSON text: %s");
errorMessages.put(ERROR_WEB_HTML_TEXT_DECODE_FAILED,
......@@ -320,10 +321,12 @@ public final class ErrorMessages {
"The specified request headers are not valid: element %s is not a list");
errorMessages.put(ERROR_WEB_REQUEST_HEADER_NOT_TWO_ELEMENTS,
"The specified request headers are not valid: element %s does not contain two elements");
errorMessages.put(ERROR_WEB_BUILD_POST_DATA_NOT_LIST,
"Unable to build post data: element %s is not a list");
errorMessages.put(ERROR_WEB_BUILD_POST_DATA_NOT_TWO_ELEMENTS,
"Unable to build post data: element %s does not contain two elements");
errorMessages.put(ERROR_WEB_BUILD_REQUEST_DATA_NOT_LIST,
"Unable to build request data: element %s is not a list");
errorMessages.put(ERROR_WEB_BUILD_REQUEST_DATA_NOT_TWO_ELEMENTS,
"Unable to build request data: element %s does not contain two elements");
errorMessages.put(ERROR_WEB_UNABLE_TO_DELETE,
"Unable to delete a resource with the specified URL: %s");
// Contact picker (and PhoneNumberPicker) errors
errorMessages.put(ERROR_PHONE_UNSUPPORTED_CONTACT_PICKER,
"The software used in this app cannot extract contacts from this type of phone.");
......
......@@ -89,13 +89,13 @@ public class WebTest extends TestCase {
}
}
public void testbuildPostData() throws Exception {
public void testbuildRequestData() throws Exception {
List<Object> list = new ArrayList<Object>();
list.add(YailList.makeList(new String[] { "First Name", "Barack" }));
list.add(YailList.makeList(new String[] { "Last Name", "Obama" }));
list.add(YailList.makeList(new String[] { "Title", "President of the United States" }));
assertEquals("First+Name=Barack&Last+Name=Obama&Title=President+of+the+United+States",
web.buildPostData(YailList.makeList(list)));
web.buildRequestData(YailList.makeList(list)));
list.clear();
list.add(YailList.makeList(new String[] { "First Name", "Barack" }));
......@@ -103,10 +103,10 @@ public class WebTest extends TestCase {
list.add(YailList.makeList(new String[] { "Last Name", "Obama" }));
list.add(YailList.makeList(new String[] { "Title", "President of the United States" }));
try {
web.buildPostData(YailList.makeList(list));
web.buildRequestData(YailList.makeList(list));
fail();
} catch (Web.BuildPostDataException e) {
assertEquals(ErrorMessages.ERROR_WEB_BUILD_POST_DATA_NOT_LIST, e.errorNumber);
} catch (Web.BuildRequestDataException e) {
assertEquals(ErrorMessages.ERROR_WEB_BUILD_REQUEST_DATA_NOT_LIST, e.errorNumber);
assertEquals(2, e.index);
}
......@@ -116,10 +116,10 @@ public class WebTest extends TestCase {
list.add(YailList.makeList(new String[] { "Title", "President of the United States",
"This list has too many items" }));
try {
web.buildPostData(YailList.makeList(list));
web.buildRequestData(YailList.makeList(list));
fail();
} catch (Web.BuildPostDataException e) {
assertEquals(ErrorMessages.ERROR_WEB_BUILD_POST_DATA_NOT_TWO_ELEMENTS, e.errorNumber);
} catch (Web.BuildRequestDataException e) {
assertEquals(ErrorMessages.ERROR_WEB_BUILD_REQUEST_DATA_NOT_TWO_ELEMENTS, e.errorNumber);
assertEquals(3, e.index);
}
......@@ -129,10 +129,10 @@ public class WebTest extends TestCase {
list.add(YailList.makeList(new String[] { "Title", "President of the United States" }));
list.add(YailList.makeList(new String[] { "This list has too few items" }));
try {
web.buildPostData(YailList.makeList(list));
web.buildRequestData(YailList.makeList(list));
fail();
} catch (Web.BuildPostDataException e) {
assertEquals(ErrorMessages.ERROR_WEB_BUILD_POST_DATA_NOT_TWO_ELEMENTS, e.errorNumber);
} catch (Web.BuildRequestDataException e) {
assertEquals(ErrorMessages.ERROR_WEB_BUILD_REQUEST_DATA_NOT_TWO_ELEMENTS, e.errorNumber);
assertEquals(4, e.index);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment