Commit b5e89d7a authored by Red Panda Apps's avatar Red Panda Apps Committed by Jeffrey Schiller

Added UrlDecode function (#1147)

Added UrlDecode function to the Web Component
parent 9b943f9e
...@@ -5509,6 +5509,10 @@ public interface OdeMessages extends Messages { ...@@ -5509,6 +5509,10 @@ public interface OdeMessages extends Messages {
@DefaultMessage("UriEncode") @DefaultMessage("UriEncode")
@Description("") @Description("")
String UriEncodeMethods(); String UriEncodeMethods();
@DefaultMessage("UriDecode")
@Description("")
String UriDecodeMethods();
@DefaultMessage("CanGoBack") @DefaultMessage("CanGoBack")
@Description("") @Description("")
......
...@@ -1461,6 +1461,11 @@ public final class YoungAndroidFormUpgrader { ...@@ -1461,6 +1461,11 @@ public final class YoungAndroidFormUpgrader {
// No properties need to be modified to upgrade to version 4. // No properties need to be modified to upgrade to version 4.
srcCompVersion = 4; srcCompVersion = 4;
} }
if (srcCompVersion < 5) {
// The UriDecode method was added.
// No properties need to be modified to upgrade to version 5.
srcCompVersion = 5;
}
return srcCompVersion; return srcCompVersion;
} }
......
...@@ -2506,7 +2506,10 @@ Blockly.Versioning.AllUpgradeMaps = ...@@ -2506,7 +2506,10 @@ Blockly.Versioning.AllUpgradeMaps =
3: "ai1CantDoUpgrade", // Just indicates we couldn't do upgrade even if we wanted to 3: "ai1CantDoUpgrade", // Just indicates we couldn't do upgrade even if we wanted to
// AI2: Added method XMLTextDecode // AI2: Added method XMLTextDecode
4: "noUpgrade" 4: "noUpgrade",
// AI2: Added method UriDecode
5: "noUpgrade"
}, // End Web upgraders }, // End Web upgraders
......
...@@ -1108,7 +1108,9 @@ public class YaVersion { ...@@ -1108,7 +1108,9 @@ public class YaVersion {
// - PUT and DELETE Actions added (PutText, PutTextWithEncoding, PutFile, and Delete). // - PUT and DELETE Actions added (PutText, PutTextWithEncoding, PutFile, and Delete).
// For WEB_COMPONENT_VERSION 4: // For WEB_COMPONENT_VERSION 4:
// - Added method XMLTextDecode // - Added method XMLTextDecode
public static final int WEB_COMPONENT_VERSION = 4; // For WEB_COMPONENT_VERSION 5:
// - Added method UriDecode
public static final int WEB_COMPONENT_VERSION = 5;
// For WEBVIEWER_COMPONENT_VERSION 2: // For WEBVIEWER_COMPONENT_VERSION 2:
// - The CanGoForward and CanGoBack methods were added // - The CanGoForward and CanGoBack methods were added
......
...@@ -53,6 +53,7 @@ import java.net.ProtocolException; ...@@ -53,6 +53,7 @@ import java.net.ProtocolException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.net.URLDecoder;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -699,6 +700,26 @@ public class Web extends AndroidNonvisibleComponent implements Component { ...@@ -699,6 +700,26 @@ public class Web extends AndroidNonvisibleComponent implements Component {
} }
} }
/**
* Decodes the encoded text value.
*
* @param text the text to encode
* @return the decoded text
*/
@SimpleFunction
public String UriDecode(String text) {
try {
return URLDecoder.decode(text, "UTF-8");
} catch (UnsupportedEncodingException e) {
// If UTF-8 is not supported, we're in big trouble!
// According to Javadoc and Android documentation for java.nio.charset.Charset, UTF-8 is
// available on every Java implementation.
Log.e(LOG_TAG, "UTF-8 is unsupported?", e);
return "";
}
}
/** /**
* Decodes the given JSON encoded value to produce a corresponding AppInventor value. * Decodes the given JSON encoded value to produce a corresponding AppInventor value.
* A JSON list [x, y, z] decodes to a list (x y z), A JSON object with name A and value B, * A JSON list [x, y, z] decodes to a list (x y z), A JSON object with name A and value B,
......
...@@ -762,6 +762,8 @@ delimiter byte value is received. </dd> ...@@ -762,6 +762,8 @@ delimiter byte value is received. </dd>
<dd>Performs an HTTP PUT request using the Url property and the specified text.<br>The characters of the text are encoded using the given encoding.<br>If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.<br>If the SaveResponse property is false, the GotText event will be triggered.</dd> <dd>Performs an HTTP PUT request using the Url property and the specified text.<br>The characters of the text are encoded using the given encoding.<br>If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.<br>If the SaveResponse property is false, the GotText event will be triggered.</dd>
<dt><code>text UriEncode(text text)</code></dt> <dt><code>text UriEncode(text text)</code></dt>
<dd>Encodes the given text value so that it can be used in a URL.</dd> <dd>Encodes the given text value so that it can be used in a URL.</dd>
<dt><code>text UriDecode(text text)</code></dt>
<dd>Decodes the encoded text value so that the values aren't URL encoded anymore.</dd>
<dt><code>any XMLTextDecode(text XmlText)</code></dt> <dt><code>any XMLTextDecode(text XmlText)</code></dt>
<dd>Decodes the given XML string to produce a list structure. See the App Inventor documentation on "Other topics, notes, and details" for information.</dd> <dd>Decodes the given XML string to produce a list structure. See the App Inventor documentation on "Other topics, notes, and details" for information.</dd>
</dl> </dl>
......
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