From c3586c163519565b3ed7e5b6caa63c2529bf7011 Mon Sep 17 00:00:00 2001 From: 258767-shengyu <1qaz2wsx> Date: Wed, 28 Jul 2021 10:36:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/botlibre/sdk/BOTlibreCredentials.java | 18 +- .../java/org/botlibre/sdk/Credentials.java | 140 +- .../java/org/botlibre/sdk/SDKConnection.java | 1742 +++++++++-------- .../java/org/botlibre/sdk/SDKException.java | 30 +- .../sdk/ability/BotSearchAbility.java | 79 +- .../botlibre/sdk/ability/EmotionalState.java | 33 - .../botlibre/sdk/ability/LibreAbility.java | 108 +- .../botlibre/sdk/ability/ListTagAbility.java | 2 +- .../sdk/ability/ListTemplateView.java | 39 +- .../botlibre/sdk/ability/LoginAbility.java | 72 +- .../botlibre/sdk/ability/SearchAbility.java | 521 ++--- .../sdk/ability/actions/HttpChatAction.java | 76 +- .../ability/actions/HttpConnectAction.java | 6 +- .../sdk/ability/actions/HttpCreateAction.java | 90 +- .../ability/actions/HttpCreateUserAction.java | 59 +- .../actions/HttpFetchChatAvatarAction.java | 57 +- .../actions/HttpFetchOrCreateAction.java | 48 - .../ability/actions/HttpFetchWarAction.java | 15 +- .../ability/actions/HttpFlagIssueAction.java | 44 +- .../ability/actions/HttpFlagUserAction.java | 45 +- .../actions/HttpGetInstancesAction.java | 12 +- .../ability/actions/HttpGetPostsAction.java | 68 +- .../sdk/ability/actions/HttpResultAction.java | 8 +- .../sdk/ability/actions/HttpUIAction.java | 68 +- .../ability/actions/HttpUIResultAction.java | 72 +- .../sdk/ability/avatar/AvatarSelection.java | 42 +- .../ability/listener/LanguageListener.java | 12 +- .../sdk/ability/listener/SelectListener.java | 12 +- .../sdk/ability/war/ChatWarConfig.java | 66 +- .../sdk/ability/war/HttpChatWarAction.java | 50 +- .../sdk/ability/war/StartWarAbility.java | 2 +- .../org/botlibre/sdk/config/AvatarMedia.java | 201 +- .../botlibre/sdk/config/AvatarMessage.java | 80 - .../botlibre/sdk/config/BotModeConfig.java | 57 - .../org/botlibre/sdk/config/BrowseConfig.java | 92 +- .../botlibre/sdk/config/ChannelConfig.java | 98 +- .../org/botlibre/sdk/config/ChatConfig.java | 138 +- .../org/botlibre/sdk/config/ChatResponse.java | 150 +- .../java/org/botlibre/sdk/config/Config.java | 118 +- .../botlibre/sdk/config/ContentConfig.java | 44 - .../sdk/config/ConversationConfig.java | 50 - .../org/botlibre/sdk/config/DomainConfig.java | 54 +- .../org/botlibre/sdk/config/ForumConfig.java | 76 +- .../botlibre/sdk/config/ForumPostConfig.java | 329 ++-- .../botlibre/sdk/config/GraphicConfig.java | 96 +- .../org/botlibre/sdk/config/InputConfig.java | 61 - .../botlibre/sdk/config/InstanceConfig.java | 126 +- .../org/botlibre/sdk/config/IssueConfig.java | 301 +-- .../sdk/config/IssueTrackerConfig.java | 63 - .../botlibre/sdk/config/LearningConfig.java | 182 +- .../org/botlibre/sdk/config/MediaConfig.java | 53 - .../sdk/config/OfflineTemplateConfig.java | 119 +- .../botlibre/sdk/config/ResponseConfig.java | 334 ++-- .../sdk/config/ResponseSearchConfig.java | 57 - .../org/botlibre/sdk/config/ScriptConfig.java | 73 +- .../sdk/config/ScriptSourceConfig.java | 163 +- .../java/org/botlibre/sdk/config/Speech.java | 48 - .../botlibre/sdk/config/TrainingConfig.java | 60 - .../botlibre/sdk/config/UserAdminConfig.java | 56 - .../org/botlibre/sdk/config/UserConfig.java | 292 +-- .../sdk/config/UserMessageConfig.java | 100 - .../org/botlibre/sdk/config/VoiceConfig.java | 86 +- .../botlibre/sdk/config/WebMediumConfig.java | 468 ++--- .../org/botlibre/sdk/util/TextStream.java | 1252 ++++++------ .../java/org/botlibre/sdk/util/Utils.java | 476 ++--- .../org/botlibre/sdk/BOTlibreCredentials.java | 18 +- .../java/org/botlibre/sdk/SDKException.java | 30 +- .../sdk/ability/BotSearchAbility.java | 94 +- .../botlibre/sdk/ability/EmotionalState.java | 14 +- .../botlibre/sdk/ability/LoginAbility.java | 68 +- .../sdk/ability/MicConfigAbility.java | 1 + .../botlibre/sdk/ability/SearchAbility.java | 478 ++--- .../ability/actions/HttpCreateUserAction.java | 59 +- .../sdk/ability/actions/HttpFetchAction.java | 166 +- .../ability/actions/HttpFlagUserAction.java | 47 +- .../actions/HttpGetAvatarMediaAction.java | 57 +- .../actions/HttpGetLearningAction.java | 68 +- .../actions/HttpGetTemplatesAction.java | 18 +- .../sdk/ability/actions/HttpUIAction.java | 68 +- .../ability/actions/HttpUIResultAction.java | 72 +- .../sdk/ability/avatar/AvatarSelection.java | 42 +- .../sdk/ability/war/ChatWarConfig.java | 66 +- .../sdk/ability/war/HttpChatWarAction.java | 50 +- .../sdk/ability/war/StartWarAbility.java | 10 +- .../org/botlibre/sdk/config/AvatarMedia.java | 199 +- .../botlibre/sdk/config/AvatarMessage.java | 94 +- .../botlibre/sdk/config/BotModeConfig.java | 54 +- .../org/botlibre/sdk/config/BrowseConfig.java | 90 +- .../botlibre/sdk/config/ChannelConfig.java | 92 +- .../org/botlibre/sdk/config/ChatConfig.java | 138 +- .../org/botlibre/sdk/config/ChatResponse.java | 150 +- .../java/org/botlibre/sdk/config/Config.java | 118 +- .../botlibre/sdk/config/ContentConfig.java | 58 +- .../sdk/config/ConversationConfig.java | 42 +- .../org/botlibre/sdk/config/DomainConfig.java | 54 +- .../org/botlibre/sdk/config/ForumConfig.java | 76 +- .../botlibre/sdk/config/ForumPostConfig.java | 305 +-- .../botlibre/sdk/config/GraphicConfig.java | 96 +- .../org/botlibre/sdk/config/InputConfig.java | 54 +- .../botlibre/sdk/config/InstanceConfig.java | 126 +- .../org/botlibre/sdk/config/IssueConfig.java | 301 +-- .../sdk/config/IssueTrackerConfig.java | 68 +- .../botlibre/sdk/config/LearningConfig.java | 182 +- .../org/botlibre/sdk/config/MediaConfig.java | 76 +- .../sdk/config/OfflineTemplateConfig.java | 119 +- .../botlibre/sdk/config/ResponseConfig.java | 334 ++-- .../sdk/config/ResponseSearchConfig.java | 60 +- .../org/botlibre/sdk/config/ScriptConfig.java | 73 +- .../sdk/config/ScriptSourceConfig.java | 163 +- .../java/org/botlibre/sdk/config/Speech.java | 40 +- .../botlibre/sdk/config/TrainingConfig.java | 61 +- .../botlibre/sdk/config/UserAdminConfig.java | 54 +- .../org/botlibre/sdk/config/UserConfig.java | 245 ++- .../sdk/config/UserMessageConfig.java | 128 +- .../org/botlibre/sdk/config/VoiceConfig.java | 86 +- .../botlibre/sdk/config/WebMediumConfig.java | 468 ++--- .../org/botlibre/sdk/util/TextStream.java | 1252 ++++++------ .../java/org/botlibre/sdk/SDKException.java | 30 +- .../botlibre/sdk/ability/LoginAbility.java | 70 +- .../org/botlibre/sdk/config/AvatarConfig.java | 1003 +++++----- .../org/botlibre/sdk/config/AvatarMedia.java | 201 +- .../org/botlibre/sdk/config/BrowseConfig.java | 92 +- .../botlibre/sdk/config/ChannelConfig.java | 94 +- .../org/botlibre/sdk/config/ChatConfig.java | 138 +- .../org/botlibre/sdk/config/ChatResponse.java | 150 +- .../java/org/botlibre/sdk/config/Config.java | 118 +- .../org/botlibre/sdk/config/ForumConfig.java | 76 +- .../botlibre/sdk/config/GraphicConfig.java | 96 +- .../botlibre/sdk/config/InstanceConfig.java | 126 +- .../org/botlibre/sdk/config/IssueConfig.java | 301 +-- .../botlibre/sdk/config/LearningConfig.java | 182 +- .../sdk/config/OfflineTemplateConfig.java | 119 +- .../botlibre/sdk/config/ResponseConfig.java | 334 ++-- .../org/botlibre/sdk/config/ScriptConfig.java | 77 +- .../sdk/config/ScriptSourceConfig.java | 151 +- .../org/botlibre/sdk/config/UserConfig.java | 244 +-- .../org/botlibre/sdk/config/VoiceConfig.java | 86 +- .../botlibre/sdk/config/WebMediumConfig.java | 468 ++--- .../org/botlibre/sdk/BOTlibreCredentials.java | 18 +- .../java/org/botlibre/sdk/Credentials.java | 118 +- .../java/org/botlibre/sdk/SDKException.java | 30 +- .../sdk/ability/BotSearchAbility.java | 79 +- .../botlibre/sdk/ability/EmotionalState.java | 33 - .../botlibre/sdk/ability/LibreAbility.java | 32 +- .../sdk/ability/ListTemplateView.java | 38 +- .../sdk/ability/actions/HttpChatAction.java | 77 +- .../ability/actions/HttpCreateUserAction.java | 63 +- .../actions/HttpFetchChatAvatarAction.java | 57 +- .../actions/HttpGetTemplatesAction.java | 50 +- .../sdk/ability/actions/HttpUIAction.java | 68 +- .../ability/actions/HttpUIResultAction.java | 72 +- .../sdk/ability/avatar/AvatarSelection.java | 42 +- .../ability/listener/LanguageListener.java | 12 +- .../sdk/ability/listener/SelectListener.java | 12 +- .../sdk/ability/war/ChatWarConfig.java | 66 +- .../sdk/ability/war/HttpChatWarAction.java | 50 +- .../org/botlibre/sdk/config/AvatarConfig.java | 1066 +++++----- .../org/botlibre/sdk/config/AvatarMedia.java | 201 +- .../botlibre/sdk/config/AvatarMessage.java | 96 +- .../botlibre/sdk/config/BotModeConfig.java | 54 +- .../org/botlibre/sdk/config/BrowseConfig.java | 92 +- .../botlibre/sdk/config/ChannelConfig.java | 94 +- .../org/botlibre/sdk/config/ChatConfig.java | 138 +- .../org/botlibre/sdk/config/ChatResponse.java | 150 +- .../java/org/botlibre/sdk/config/Config.java | 118 +- .../botlibre/sdk/config/ContentConfig.java | 62 +- .../sdk/config/ConversationConfig.java | 44 +- .../org/botlibre/sdk/config/DomainConfig.java | 54 +- .../org/botlibre/sdk/config/ForumConfig.java | 76 +- .../botlibre/sdk/config/ForumPostConfig.java | 329 ++-- .../botlibre/sdk/config/GraphicConfig.java | 96 +- .../org/botlibre/sdk/config/InputConfig.java | 54 +- .../botlibre/sdk/config/InstanceConfig.java | 126 +- .../org/botlibre/sdk/config/IssueConfig.java | 301 +-- .../sdk/config/IssueTrackerConfig.java | 68 +- .../botlibre/sdk/config/LearningConfig.java | 182 +- .../org/botlibre/sdk/config/MediaConfig.java | 78 +- .../sdk/config/OfflineTemplateConfig.java | 119 +- .../botlibre/sdk/config/ResponseConfig.java | 334 ++-- .../sdk/config/ResponseSearchConfig.java | 60 +- .../org/botlibre/sdk/config/ScriptConfig.java | 73 +- .../sdk/config/ScriptSourceConfig.java | 163 +- .../java/org/botlibre/sdk/config/Speech.java | 40 +- .../botlibre/sdk/config/TrainingConfig.java | 61 +- .../botlibre/sdk/config/UserAdminConfig.java | 54 +- .../org/botlibre/sdk/config/UserConfig.java | 292 +-- .../sdk/config/UserMessageConfig.java | 128 +- .../org/botlibre/sdk/config/VoiceConfig.java | 86 +- .../botlibre/sdk/config/WebMediumConfig.java | 468 ++--- .../org/botlibre/sdk/util/TextStream.java | 1252 ++++++------ .../java/org/botlibre/sdk/util/Utils.java | 516 ++--- 191 files changed, 13912 insertions(+), 14757 deletions(-) delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/Speech.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java index 1b2e369..83e57f1 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java @@ -23,14 +23,14 @@ package org.botlibre.sdk; * http://www.botlibre.com */ public class BOTlibreCredentials extends Credentials { - public static final String DOMAIN = "www.botlibre.com"; - public static final String APP = ""; - public static final String PATH = "/rest/api"; + public static final String DOMAIN = "www.botlibre.com"; + public static final String APP = ""; + public static final String PATH = "/rest/api"; - public BOTlibreCredentials(String applicationId) { - this.host = DOMAIN; - this.app = APP; - this.url = "https://" + DOMAIN + APP + PATH; - this.applicationId = applicationId; - } + public BOTlibreCredentials(String applicationId) { + this.host = DOMAIN; + this.app = APP; + this.url = "https://" + DOMAIN + APP + PATH; + this.applicationId = applicationId; + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/Credentials.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/Credentials.java index 2735a7a..3f13b66 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/Credentials.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/Credentials.java @@ -24,84 +24,84 @@ package org.botlibre.sdk; * You can obtain your application id from your user details page on the hosting website. */ public class Credentials { - public String host = ""; - public String app = ""; - public String url = ""; - /** - * Your application's unique identifier. - * You can obtain your application id from your user details page on the hosting website. - */ - public String applicationId = ""; + public String host = ""; + public String app = ""; + public String url = ""; + /** + * Your application's unique identifier. + * You can obtain your application id from your user details page on the hosting website. + */ + public String applicationId = ""; - public Credentials() { - } + public Credentials() { + } - /** - * Creates a new credentials for the service host url, and the application id. - * - * @param url url - * @param applicationId applicationId - */ - public Credentials(String url, String applicationId) { - this.url = url; - this.applicationId = applicationId; - } + /** + * Creates a new credentials for the service host url, and the application id. + * + * @param url url + * @param applicationId applicationId + */ + public Credentials(String url, String applicationId) { + this.url = url; + this.applicationId = applicationId; + } - public String getUrl() { - return url; - } + public String getUrl() { + return url; + } - /** - * Sets the hosted service server url, i.e. http://www.paphuslivechat.com - * - * @param url url - */ - public void setUrl(String url) { - this.url = url; - } + /** + * Sets the hosted service server url, i.e. http://www.paphuslivechat.com + * + * @param url url + */ + public void setUrl(String url) { + this.url = url; + } - public String getHost() { - return host; - } + public String getHost() { + return host; + } - /** - * Sets the server host name, i.e. www.paphuslivechat.com - * - * @param host host - */ - public void setHost(String host) { - this.host = host; - } + /** + * Sets the server host name, i.e. www.paphuslivechat.com + * + * @param host host + */ + public void setHost(String host) { + this.host = host; + } - public String getApp() { - return app; - } + public String getApp() { + return app; + } - /** - * Sets an app url postfix, this is normally not required, i.e. "". - * - * @param app app - */ - public void setApp(String app) { - this.app = app; - } + /** + * Sets an app url postfix, this is normally not required, i.e. "". + * + * @param app app + */ + public void setApp(String app) { + this.app = app; + } - /** - * Returns your application's unique identifier. - * - * @return getApplicationId - */ - public String getApplicationId() { - return applicationId; - } + /** + * Returns your application's unique identifier. + * + * @return getApplicationId + */ + public String getApplicationId() { + return applicationId; + } - /** - * Sets your application's unique identifier. - * You can obtain your application id from your user details page on the hosting website. - * - * @param applicationId - */ - public void setApplicationId(String applicationId) { - this.applicationId = applicationId; - } + /** + * Sets your application's unique identifier. + * You can obtain your application id from your user details page on the hosting website. + * + * @param applicationId + */ + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java index 39bdafc..5dcd200 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java @@ -79,873 +79,877 @@ import java.util.List; * */ public class SDKConnection { - private static final String[] types = new String[]{"Bots", "Forums", "Graphics", "Live Chat", "Domains", "Scripts", "IssueTracker"}; - private static final String[] accessModes = new String[]{"Everyone", "Users", "Members", "Administrators"}; - private static final String[] mediaAccessModes = new String[]{"Everyone", "Users", "Members", "Administrators", "Disabled"}; - - protected String url; - protected UserConfig user; - protected DomainConfig domain; - protected Credentials credentials; - protected boolean debug = false; - - protected SDKException exception; - - /** - * Create an SDK connection. - */ - public SDKConnection() { - } - - /** - * Use the Credentials subclass specific to your server. - * - * @param credentials credentials - */ - public SDKConnection(Credentials credentials) { - this.credentials = credentials; - this.url = credentials.url; - } - - /** - * The user credentials are soted in the connection, and used on subsequent calls. - * - * @param config config - * @return The user credentials are soted in the connection, and used on subsequent calls. - */ - public UserConfig connect(UserConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-user", config.toXML()); - Element root = parse(xml); - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - this.user = user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - return this.user; - } - - /** - * Execute the custom API. - * - * @param api api - * @param config config - * @param result result - * @return Execute the custom API. - */ - public Config custom(String api, Config config, Config result) { - config.addCredentials(this); - String xml = POST(this.url + "/" + api, config.toXML()); - Element root = parse(xml); - try { - result.parseXML(root); - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - return result; - } - - /** - * Any browse or query request will be specific to the domain's content. - * - * @param config config - * @return Any browse or query request will be specific to the domain's content. - */ - public DomainConfig connect(DomainConfig config) { - this.domain = fetch(config); - return this.domain; - } - - /** - * An SDKConnection does not keep a live connection, but this resets its connected user and domain. - */ - public void disconnect() { - this.user = null; - this.domain = null; - } - - /** - * Fetch the user details. - * - * @param config config - * @return Fetch the user details. - */ - public UserConfig fetch(UserConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/view-user", config.toXML()); - Element root = parse(xml); - - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - return user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Fetch the URL for the image from the server. - * - * @param image image - * @return Fetch the URL for the image from the server. - */ - public URL fetchImage(String image) { - try { - return new URL("http://" + this.credentials.host + this.credentials.app + "/" + image); - } catch (Exception exception) { - this.exception = new SDKException(exception); - throw this.exception; - } - } - - /** - * Create a new user. - * - * @param ability ability - * @param config config - * @return Create a new user. - */ - public UserConfig create(Ability ability,UserConfig config) { - config.addCredentials(this); - String xml = POSTUpdate(ability,this.url + "/create-user", config.toXML()); - Element root = parse(xml); - try { - UserConfig user = new UserConfig(); - user.parseXML(root); - this.user = user; - return user; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new forum post. - * - * @param config config - * @return Create a new forum post. - */ - public ForumPostConfig create(ForumPostConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-forum-post", config.toXML()); - Element root = parse(xml); - try { - ForumPostConfig post = new ForumPostConfig(); - post.parseXML(root); - return post; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create a new issue. - * - * @param config config - * @return Create a new issue. - */ - public IssueConfig create(IssueConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-issue", config.toXML()); - Element root = parse(xml); - try { - IssueConfig issue = new IssueConfig(); - issue.parseXML(root); - return issue; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Fetch the content details from the server. - * - * @param config config - * @param - * @return Fetch the content details from the server. - */ - @SuppressWarnings("unchecked") - public T fetch(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/check-" + config.getType(), config.toXML()); - Element root = parse(xml); - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Create the new content. - * The content will be returned with its new id. - * - * @param config config - * @param - * @return Create the new content. - */ - @SuppressWarnings("unchecked") - public T create(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/create-" + config.getType(), config.toXML()); - Element root = parse(xml); - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Update the content. - * - * @param config config - * @param - * @return Update the content. - */ - @SuppressWarnings("unchecked") - public T update(T config) { - config.addCredentials(this); - String xml = POST(this.url + "/update-" + config.getType(), config.toXML()); - Element root = parse(xml); - try { - config = (T)config.getClass().newInstance(); - config.parseXML(root); - return config; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - /** - * Permanently delete the content with the id. - * - * @param config config - */ - public void delete(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-" + config.getType(), config.toXML()); - if(this.domain!=null && this.domain.id.equals(config.id) && config.getType().equals("domain") ){ - domain=null; - } - } - - /** - * Permanently delete the forum post with the id. - * - * @param config config - */ - public void delete(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-forum-post", config.toXML()); - } - - /** - * Permanently delete the issue with the id. - * - * @param config config - */ - public void delete(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-issue", config.toXML()); - } - - /** - * Permanently delete the response, greetings, or default response with the response id (and question id). - * - * @param config config - */ - public void delete(ResponseConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-response", config.toXML()); - } - - /** - * Permanently delete the avatar media. - * - * @param config config - */ - public void delete(AvatarMedia config) { - config.addCredentials(this); - POST(this.url + "/delete-avatar-media", config.toXML()); - } - - /** - * Permanently delete the avatar background. - * - * @param config config - */ - public void deleteAvatarBackground(AvatarConfig config) { - config.addCredentials(this); - POST(this.url + "/delete-avatar-background", config.toXML()); - } - - /** - * Save the avatar media tags. - * - * @param config config - */ - public void saveAvatarMedia(AvatarMedia config) { - config.addCredentials(this); - POST(this.url + "/save-avatar-media", config.toXML()); - } - - /** - * Flag the content as offensive, a reason is required. - * - * @param config config - */ - public void flag(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-" + config.getType(), config.toXML()); - } - - /** - * Subscribe for email updates for the post. - * - * @param config config - */ - public void subscribe(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-post", config.toXML()); - } - - /** - * Subscribe for email updates for the issue. - * - * @param config config - */ - public void subscribe(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-issue", config.toXML()); - } - - /** - * Subscribe for email updates for the forum. - * - * @param config config - */ - public void subscribe(ForumConfig config) { - config.addCredentials(this); - POST(this.url + "/subscribe-forum", config.toXML()); - } - - /** - * Unsubscribe from email updates for the post. - * - * @param config config - */ - public void unsubscribe(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-post", config.toXML()); - } - - /** - * Unsubscribe from email updates for the issue. - * - * @param config config - */ - public void unsubscribe(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-issue", config.toXML()); - } - - /** - * Unsubscribe from email updates for the forum. - * - * @param config config - */ - public void unsubscribe(ForumConfig config) { - config.addCredentials(this); - POST(this.url + "/unsubscribe-forum", config.toXML()); - } - - /** - * Thumbs up the content. - * - * @param config config - */ - public void thumbsUp(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-" + config.getType(), config.toXML()); - } - - /** - * Thumbs down the content. - * - * @param config config - */ - public void thumbsDown(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-" + config.getType(), config.toXML()); - } - - /** - * Rate the content. - * - * @param config config - */ - public void star(WebMediumConfig config) { - config.addCredentials(this); - POST(this.url + "/star-" + config.getType(), config.toXML()); - } - - /** - * Thumbs up the content. - * - * @param config config - */ - public void thumbsUp(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-post", config.toXML()); - } - - /** - * Thumbs down the content. - * - * @param config config - */ - public void thumbsDown(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-post", config.toXML()); - } - - /** - * Rate the content. - * - * @param config config - */ - public void star(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/star-post", config.toXML()); - } - - /** - * Flag the forum post as offensive, a reason is required. - * - * @param config config - */ - public void flag(ForumPostConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-forum-post", config.toXML()); - } - - /** - * Thumbs up the content. - * - * @param config config - */ - public void thumbsUp(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-up-issue", config.toXML()); - } - - /** - * Thumbs down the content. - * - * @param config config - */ - public void thumbsDown(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/thumbs-down-issue", config.toXML()); - } - - /** - * Rate the content. - * - * @param config config - */ - public void star(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/star-issue", config.toXML()); - } - - /** - * Flag the forum post as offensive, a reason is required. - * - * @param config config - */ - public void flag(IssueConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-issue", config.toXML()); - } - - /** - * Flag the user post as offensive, a reason is required. - * - * @param config config - */ - public void flag(UserConfig config) { - config.addCredentials(this); - POST(this.url + "/flag-user", config.toXML()); - } - - /** - * Process the bot chat message and return the bot's response. - * - * @param config config - * @return Process the bot chat message and return the bot's response. - */ - public ChatResponse chat(ChatConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/post-chat", config.toXML()); - Element root = parse(xml); - try { - ChatResponse response = new ChatResponse(); - response.parseXML(root); - return response; - } catch (Exception exception) { - this.exception = SDKException.parseFailure(exception); - throw this.exception; - } - } - - /** - * Return the list of forum posts for the forum browse criteria. - * - * @param config config - * @return Return the list of forum posts for the forum browse criteria. - */ - public List getPosts(BrowseConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-forum-posts", config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - ForumPostConfig post = new ForumPostConfig(); - post.parseXML((Element)root.getChildNodes().item(index)); - instances.add(post); - } - return instances; - } - /** - * Return the bot's default responses. - * - * @param config config - * @return Return the bot's default responses. - */ - public List getDefaultResponses(InstanceConfig config) { - config.addCredentials(this); - String xml = POST(this.url + "/get-default-responses", config.toXML()); - List defaultResponses = new ArrayList(); - Element root = parse(xml); - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - defaultResponses.add(((Element)root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); - } - return defaultResponses; - } - /** - * Return the list of content for the browse criteria. - * The type defines the content type (one of Bot, Forum, Channel, Domain). - * - * @param ability ability - * @param config config - * @return browse - */ - public List browse(Ability ability,BrowseConfig config) { - config.addCredentials(this); - String type = ""; - if (config.type.equals("Bot")) { - type = "/get-instances"; - } else { - type = "/get-" + config.type.toLowerCase() + "s"; - } - String xml = POSTUpdate(ability,this.url + type, config.toXML()); - List instances = new ArrayList(); - Element root = parse(xml); - for (int index = 0; index < root.getChildNodes().getLength(); index++) { - WebMediumConfig instance = null; - if (config.type.equals("Bot")) { - instance = new InstanceConfig(); - } else if (config.type.equals("Forum")) { - instance = new ForumConfig(); - } else if (config.type.equals("Channel")) { - instance = new ChannelConfig(); - } else if (config.type.equals("Domain")) { - instance = new DomainConfig(); - } else if (config.type.equals("Avatar")) { - instance = new AvatarConfig(); - } else if (config.type.equals("Script")) { - instance = new ScriptConfig(); - }else if (config.type.equals("Graphic")) { - instance = new GraphicConfig(); - } - instance.parseXML((Element)root.getChildNodes().item(index)); - instances.add(instance); - } - return instances; - } - /** - * Return the list of content types. - * - * @return Return the list of content types. - */ - public String[] getTypes() { - return types.clone(); - } - - /** - * Return the access mode types. - * - * @return Return the access mode types. - */ - public String[] getAccessModes() { - return accessModes.clone(); - } - - /** - * Return the media access mode types. - * - * @return Return the media access mode types. - */ - public String[] getMediaAccessModes() { - return mediaAccessModes.clone(); - } - - /** - * Return the current connected user. - * - * @return Return the current connected user. - */ - public UserConfig getUser() { - return user; - } - - /** - * Set the current connected user. - * - * @param user - */ - public void setUser(UserConfig user) { - this.user = user; - } - - /** - * Return the current domain. - * - * @return Return the current domain. - */ - public DomainConfig getDomain() { - return domain; - } - - /** - * Set the current domain. - * - * @param domain domain - */ - public void setDomain(DomainConfig domain) { - this.domain = domain; - } - - /** - * Return the current application credentials. - * - * @return getCredentials - */ - public Credentials getCredentials() { - return credentials; - } - - /** - * Set the application credentials. - * - * @param credentials credentials - */ - public void setCredentials(Credentials credentials) { - this.credentials = credentials; - this.url = credentials.url; - } - - /** - * Enable debugging, debug messages will be logged to System.out. - * - * @param debug debug - */ - public void setDebug(boolean debug) { - this.debug = debug; - } - - /** - * Return the last thrown exception. - * - * @return Return the last thrown exception. - */ - public SDKException getException() { - return exception; - } - - protected void setException(SDKException exception) { - this.exception = exception; - } - - /** - * GET - * - * @param url url - * @return GET string - */ - public String GET(String url) { - if (this.debug) { - System.out.println("GET: " + url); - } - String xml = null; - try { - HttpClient httpClient = new DefaultHttpClient(); - HttpContext localContext = new BasicHttpContext(); - HttpGet httpGet = new HttpGet(url); - HttpResponse response = httpClient.execute(httpGet, localContext); - HttpEntity entity = response.getEntity(); - xml = EntityUtils.toString(entity, HTTP.UTF_8); - - if (response.getStatusLine().getStatusCode() != 200) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + xml); - return ""; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception); - throw this.exception; - } - return xml; - } - - /** - * POST - * - * @param url url - * @param xml xml - * @return POST - */ - public String POST(String url, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("XML: " + xml); - } - String result = ""; - try { - HttpClient httpClient = new DefaultHttpClient(); - HttpContext localContext = new BasicHttpContext(); - HttpPost httpPost = new HttpPost(url); - - StringEntity content = new StringEntity(xml, "utf-8"); - content.setContentType("application/xml"); - httpPost.setEntity(content); - - HttpResponse response = httpClient.execute(httpPost, localContext); - - HttpEntity entity = response.getEntity(); - if (entity != null) { - result = EntityUtils.toString(entity, HTTP.UTF_8); - } - if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { - this.exception = new SDKException("" - + response.getStatusLine().getStatusCode() - + " : " + result); - throw this.exception; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception); - throw this.exception; - } - return result; - } - - /** - * POSTUpdate - * - * @param ability ability - * @param url url - * @param xml xml - * @return POSTUpdate - */ - public String POSTUpdate(Ability ability,String url, String xml) { - if (this.debug) { - System.out.println("POST: " + url); - System.out.println("XML: " + xml); - } - String result = ""; - Response response = null; - try { - ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), - new SharedPrefsCookiePersistor(ability)); - OkHttpClient okHttpClient = new OkHttpClient.Builder() - .cookieJar(cookieJar) - .build(); - response = getResponse(okHttpClient, url,xml); - - if ((response.code() != 200) && (response.code() != 204)) { - this.exception = new SDKException(response.code()+""); - throw this.exception; - } - } catch (Exception exception) { - if (this.debug) { - exception.printStackTrace(); - } - this.exception = new SDKException(exception); - throw this.exception; - } - return response.body().toString(); - } - - /** - * getResponse - * - * @param client client - * @param url url - * @param xml xml - * @return getResponse - */ - public Response getResponse(OkHttpClient client, String url, String xml) { - // code request code here - MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); - String requestBody = xml; - Request request = new Request.Builder() - .url(url) - .post(RequestBody.create(mediaType, requestBody)) - .build(); - Call call = client.newCall(request); - try { - Response response = call.execute(); - return response; - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - /** - * parse - * - * @param xml xml - * @return parse - */ - public Element parse(String xml) { - if (this.debug) { - System.out.println(xml); - } - return (Element) new ShapeElement(); - } + private static final String[] types = new String[]{"Bots", "Forums", "Graphics", "Live Chat", "Domains", "Scripts", "IssueTracker"}; + private static final String[] accessModes = new String[]{"Everyone", "Users", "Members", "Administrators"}; + private static final String[] mediaAccessModes = new String[]{"Everyone", "Users", "Members", "Administrators", "Disabled"}; + + protected String url; + protected UserConfig user; + protected DomainConfig domain; + protected Credentials credentials; + protected boolean debug = false; + + protected SDKException exception; + + /** + * Create an SDK connection. + */ + public SDKConnection() { + } + + /** + * Use the Credentials subclass specific to your server. + * + * @param credentials credentials + */ + public SDKConnection(Credentials credentials) { + this.credentials = credentials; + this.url = credentials.url; + } + + /** + * The user credentials are soted in the connection, and used on subsequent calls. + * + * @param config config + * @return The user credentials are soted in the connection, and used on subsequent calls. + */ + public UserConfig connect(UserConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/check-user", config.toXML()); + Element root = parse(xml); + try { + UserConfig user = new UserConfig(); + user.parseXML(root); + this.user = user; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + return this.user; + } + + /** + * Execute the custom API. + * + * @param api api + * @param config config + * @param result result + * @return Execute the custom API. + */ + public Config custom(String api, Config config, Config result) { + config.addCredentials(this); + String xml = POST(this.url + "/" + api, config.toXML()); + Element root = parse(xml); + try { + result.parseXML(root); + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + return result; + } + + /** + * Any browse or query request will be specific to the domain's content. + * + * @param config config + * @return Any browse or query request will be specific to the domain's content. + */ + public DomainConfig connect(DomainConfig config) { + this.domain = fetch(config); + return this.domain; + } + + /** + * An SDKConnection does not keep a live connection, but this resets its connected user and domain. + */ + public void disconnect() { + this.user = null; + this.domain = null; + } + + /** + * Fetch the user details. + * + * @param config config + * @return Fetch the user details. + */ + public UserConfig fetch(UserConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/view-user", config.toXML()); + Element root = parse(xml); + + try { + UserConfig user = new UserConfig(); + user.parseXML(root); + return user; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Fetch the URL for the image from the server. + * + * @param image image + * @return Fetch the URL for the image from the server. + */ + public URL fetchImage(String image) { + try { + return new URL("http://" + this.credentials.host + this.credentials.app + "/" + image); + } catch (Exception exception) { + this.exception = new SDKException(exception); + throw this.exception; + } + } + + /** + * Create a new user. + * + * @param ability ability + * @param config config + * @return Create a new user. + */ + public UserConfig create(Ability ability, UserConfig config) { + config.addCredentials(this); + String xml = POSTUpdate(ability, this.url + "/create-user", config.toXML()); + Element root = parse(xml); + try { + UserConfig user = new UserConfig(); + user.parseXML(root); + this.user = user; + return user; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Create a new forum post. + * + * @param config config + * @return Create a new forum post. + */ + public ForumPostConfig create(ForumPostConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-forum-post", config.toXML()); + Element root = parse(xml); + try { + ForumPostConfig post = new ForumPostConfig(); + post.parseXML(root); + return post; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Create a new issue. + * + * @param config config + * @return Create a new issue. + */ + public IssueConfig create(IssueConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-issue", config.toXML()); + Element root = parse(xml); + try { + IssueConfig issue = new IssueConfig(); + issue.parseXML(root); + return issue; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Fetch the content details from the server. + * + * @param config config + * @param + * @return Fetch the content details from the server. + */ + @SuppressWarnings("unchecked") + public T fetch(T config) { + config.addCredentials(this); + String xml = POST(this.url + "/check-" + config.getType(), config.toXML()); + Element root = parse(xml); + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Create the new content. + * The content will be returned with its new id. + * + * @param config config + * @param + * @return Create the new content. + */ + @SuppressWarnings("unchecked") + public T create(T config) { + config.addCredentials(this); + String xml = POST(this.url + "/create-" + config.getType(), config.toXML()); + Element root = parse(xml); + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Update the content. + * + * @param config config + * @param + * @return Update the content. + */ + @SuppressWarnings("unchecked") + public T update(T config) { + config.addCredentials(this); + String xml = POST(this.url + "/update-" + config.getType(), config.toXML()); + Element root = parse(xml); + try { + config = (T) config.getClass().newInstance(); + config.parseXML(root); + return config; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Permanently delete the content with the id. + * + * @param config config + */ + public void delete(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-" + config.getType(), config.toXML()); + if (this.domain != null && this.domain.id.equals(config.id) && config.getType().equals("domain")) { + domain = null; + } + } + + /** + * Permanently delete the forum post with the id. + * + * @param config config + */ + public void delete(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-forum-post", config.toXML()); + } + + /** + * Permanently delete the issue with the id. + * + * @param config config + */ + public void delete(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-issue", config.toXML()); + } + + /** + * Permanently delete the response, greetings, or default response with the response id (and question id). + * + * @param config config + */ + public void delete(ResponseConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-response", config.toXML()); + } + + /** + * Permanently delete the avatar media. + * + * @param config config + */ + public void delete(AvatarMedia config) { + config.addCredentials(this); + POST(this.url + "/delete-avatar-media", config.toXML()); + } + + /** + * Permanently delete the avatar background. + * + * @param config config + */ + public void deleteAvatarBackground(AvatarConfig config) { + config.addCredentials(this); + POST(this.url + "/delete-avatar-background", config.toXML()); + } + + /** + * Save the avatar media tags. + * + * @param config config + */ + public void saveAvatarMedia(AvatarMedia config) { + config.addCredentials(this); + POST(this.url + "/save-avatar-media", config.toXML()); + } + + /** + * Flag the content as offensive, a reason is required. + * + * @param config config + */ + public void flag(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/flag-" + config.getType(), config.toXML()); + } + + /** + * Subscribe for email updates for the post. + * + * @param config config + */ + public void subscribe(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/subscribe-post", config.toXML()); + } + + /** + * Subscribe for email updates for the issue. + * + * @param config config + */ + public void subscribe(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/subscribe-issue", config.toXML()); + } + + /** + * Subscribe for email updates for the forum. + * + * @param config config + */ + public void subscribe(ForumConfig config) { + config.addCredentials(this); + POST(this.url + "/subscribe-forum", config.toXML()); + } + + /** + * Unsubscribe from email updates for the post. + * + * @param config config + */ + public void unsubscribe(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/unsubscribe-post", config.toXML()); + } + + /** + * Unsubscribe from email updates for the issue. + * + * @param config config + */ + public void unsubscribe(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/unsubscribe-issue", config.toXML()); + } + + /** + * Unsubscribe from email updates for the forum. + * + * @param config config + */ + public void unsubscribe(ForumConfig config) { + config.addCredentials(this); + POST(this.url + "/unsubscribe-forum", config.toXML()); + } + + /** + * Thumbs up the content. + * + * @param config config + */ + public void thumbsUp(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-up-" + config.getType(), config.toXML()); + } + + /** + * Thumbs down the content. + * + * @param config config + */ + public void thumbsDown(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-down-" + config.getType(), config.toXML()); + } + + /** + * Rate the content. + * + * @param config config + */ + public void star(WebMediumConfig config) { + config.addCredentials(this); + POST(this.url + "/star-" + config.getType(), config.toXML()); + } + + /** + * Thumbs up the content. + * + * @param config config + */ + public void thumbsUp(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-up-post", config.toXML()); + } + + /** + * Thumbs down the content. + * + * @param config config + */ + public void thumbsDown(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-down-post", config.toXML()); + } + + /** + * Rate the content. + * + * @param config config + */ + public void star(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/star-post", config.toXML()); + } + + /** + * Flag the forum post as offensive, a reason is required. + * + * @param config config + */ + public void flag(ForumPostConfig config) { + config.addCredentials(this); + POST(this.url + "/flag-forum-post", config.toXML()); + } + + /** + * Thumbs up the content. + * + * @param config config + */ + public void thumbsUp(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-up-issue", config.toXML()); + } + + /** + * Thumbs down the content. + * + * @param config config + */ + public void thumbsDown(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/thumbs-down-issue", config.toXML()); + } + + /** + * Rate the content. + * + * @param config config + */ + public void star(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/star-issue", config.toXML()); + } + + /** + * Flag the forum post as offensive, a reason is required. + * + * @param config config + */ + public void flag(IssueConfig config) { + config.addCredentials(this); + POST(this.url + "/flag-issue", config.toXML()); + } + + /** + * Flag the user post as offensive, a reason is required. + * + * @param config config + */ + public void flag(UserConfig config) { + config.addCredentials(this); + POST(this.url + "/flag-user", config.toXML()); + } + + /** + * Process the bot chat message and return the bot's response. + * + * @param config config + * @return Process the bot chat message and return the bot's response. + */ + public ChatResponse chat(ChatConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/post-chat", config.toXML()); + Element root = parse(xml); + try { + ChatResponse response = new ChatResponse(); + response.parseXML(root); + return response; + } catch (Exception exception) { + this.exception = SDKException.parseFailure(exception); + throw this.exception; + } + } + + /** + * Return the list of forum posts for the forum browse criteria. + * + * @param config config + * @return Return the list of forum posts for the forum browse criteria. + */ + public List getPosts(BrowseConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-forum-posts", config.toXML()); + List instances = new ArrayList(); + Element root = parse(xml); + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + ForumPostConfig post = new ForumPostConfig(); + post.parseXML((Element) root.getChildNodes().item(index)); + instances.add(post); + } + return instances; + } + + /** + * Return the bot's default responses. + * + * @param config config + * @return Return the bot's default responses. + */ + public List getDefaultResponses(InstanceConfig config) { + config.addCredentials(this); + String xml = POST(this.url + "/get-default-responses", config.toXML()); + List defaultResponses = new ArrayList(); + Element root = parse(xml); + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + defaultResponses.add(((Element) root.getChildNodes().item(index)).getChildNodes().item(0).getTextContent()); + } + return defaultResponses; + } + + /** + * Return the list of content for the browse criteria. + * The type defines the content type (one of Bot, Forum, Channel, Domain). + * + * @param ability ability + * @param config config + * @return browse + */ + public List browse(Ability ability, BrowseConfig config) { + config.addCredentials(this); + String type = ""; + if (config.type.equals("Bot")) { + type = "/get-instances"; + } else { + type = "/get-" + config.type.toLowerCase() + "s"; + } + String xml = POSTUpdate(ability, this.url + type, config.toXML()); + List instances = new ArrayList(); + Element root = parse(xml); + for (int index = 0; index < root.getChildNodes().getLength(); index++) { + WebMediumConfig instance = null; + if (config.type.equals("Bot")) { + instance = new InstanceConfig(); + } else if (config.type.equals("Forum")) { + instance = new ForumConfig(); + } else if (config.type.equals("Channel")) { + instance = new ChannelConfig(); + } else if (config.type.equals("Domain")) { + instance = new DomainConfig(); + } else if (config.type.equals("Avatar")) { + instance = new AvatarConfig(); + } else if (config.type.equals("Script")) { + instance = new ScriptConfig(); + } else if (config.type.equals("Graphic")) { + instance = new GraphicConfig(); + } + instance.parseXML((Element) root.getChildNodes().item(index)); + instances.add(instance); + } + return instances; + } + + /** + * Return the list of content types. + * + * @return Return the list of content types. + */ + public String[] getTypes() { + return types.clone(); + } + + /** + * Return the access mode types. + * + * @return Return the access mode types. + */ + public String[] getAccessModes() { + return accessModes.clone(); + } + + /** + * Return the media access mode types. + * + * @return Return the media access mode types. + */ + public String[] getMediaAccessModes() { + return mediaAccessModes.clone(); + } + + /** + * Return the current connected user. + * + * @return Return the current connected user. + */ + public UserConfig getUser() { + return user; + } + + /** + * Set the current connected user. + * + * @param user + */ + public void setUser(UserConfig user) { + this.user = user; + } + + /** + * Return the current domain. + * + * @return Return the current domain. + */ + public DomainConfig getDomain() { + return domain; + } + + /** + * Set the current domain. + * + * @param domain domain + */ + public void setDomain(DomainConfig domain) { + this.domain = domain; + } + + /** + * Return the current application credentials. + * + * @return getCredentials + */ + public Credentials getCredentials() { + return credentials; + } + + /** + * Set the application credentials. + * + * @param credentials credentials + */ + public void setCredentials(Credentials credentials) { + this.credentials = credentials; + this.url = credentials.url; + } + + /** + * Enable debugging, debug messages will be logged to System.out. + * + * @param debug debug + */ + public void setDebug(boolean debug) { + this.debug = debug; + } + + /** + * Return the last thrown exception. + * + * @return Return the last thrown exception. + */ + public SDKException getException() { + return exception; + } + + protected void setException(SDKException exception) { + this.exception = exception; + } + + /** + * GET + * + * @param url url + * @return GET string + */ + public String GET(String url) { + if (this.debug) { + System.out.println("GET: " + url); + } + String xml = null; + try { + HttpClient httpClient = new DefaultHttpClient(); + HttpContext localContext = new BasicHttpContext(); + HttpGet httpGet = new HttpGet(url); + HttpResponse response = httpClient.execute(httpGet, localContext); + HttpEntity entity = response.getEntity(); + xml = EntityUtils.toString(entity, HTTP.UTF_8); + + if (response.getStatusLine().getStatusCode() != 200) { + this.exception = new SDKException("" + + response.getStatusLine().getStatusCode() + + " : " + xml); + return ""; + } + } catch (Exception exception) { + if (this.debug) { + exception.printStackTrace(); + } + this.exception = new SDKException(exception); + throw this.exception; + } + return xml; + } + + /** + * POST + * + * @param url url + * @param xml xml + * @return POST + */ + public String POST(String url, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("XML: " + xml); + } + String result = ""; + try { + HttpClient httpClient = new DefaultHttpClient(); + HttpContext localContext = new BasicHttpContext(); + HttpPost httpPost = new HttpPost(url); + + StringEntity content = new StringEntity(xml, "utf-8"); + content.setContentType("application/xml"); + httpPost.setEntity(content); + + HttpResponse response = httpClient.execute(httpPost, localContext); + + HttpEntity entity = response.getEntity(); + if (entity != null) { + result = EntityUtils.toString(entity, HTTP.UTF_8); + } + if ((response.getStatusLine().getStatusCode() != 200) && (response.getStatusLine().getStatusCode() != 204)) { + this.exception = new SDKException("" + + response.getStatusLine().getStatusCode() + + " : " + result); + throw this.exception; + } + } catch (Exception exception) { + if (this.debug) { + exception.printStackTrace(); + } + this.exception = new SDKException(exception); + throw this.exception; + } + return result; + } + + /** + * POSTUpdate + * + * @param ability ability + * @param url url + * @param xml xml + * @return POSTUpdate + */ + public String POSTUpdate(Ability ability, String url, String xml) { + if (this.debug) { + System.out.println("POST: " + url); + System.out.println("XML: " + xml); + } + String result = ""; + Response response = null; + try { + ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), + new SharedPrefsCookiePersistor(ability)); + OkHttpClient okHttpClient = new OkHttpClient.Builder() + .cookieJar(cookieJar) + .build(); + response = getResponse(okHttpClient, url, xml); + + if ((response.code() != 200) && (response.code() != 204)) { + this.exception = new SDKException(response.code() + ""); + throw this.exception; + } + } catch (Exception exception) { + if (this.debug) { + exception.printStackTrace(); + } + this.exception = new SDKException(exception); + throw this.exception; + } + return response.body().toString(); + } + + /** + * getResponse + * + * @param client client + * @param url url + * @param xml xml + * @return getResponse + */ + public Response getResponse(OkHttpClient client, String url, String xml) { + // code request code here + MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); + String requestBody = xml; + Request request = new Request.Builder() + .url(url) + .post(RequestBody.create(mediaType, requestBody)) + .build(); + Call call = client.newCall(request); + try { + Response response = call.execute(); + return response; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * parse + * + * @param xml xml + * @return parse + */ + public Element parse(String xml) { + if (this.debug) { + System.out.println(xml); + } + return (Element) new ShapeElement(); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKException.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKException.java index dc730b7..2bf3c59 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKException.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKException.java @@ -25,19 +25,19 @@ package org.botlibre.sdk; */ public class SDKException extends RuntimeException { - public SDKException(Exception exception) { - super(exception.getMessage(), exception); - } - - public SDKException(String message) { - super(message); - } - - public SDKException(String message, Exception exception) { - super(message, exception); - } - - public static SDKException parseFailure(Exception exception) { - throw new SDKException("parse failure", exception); - } + public SDKException(Exception exception) { + super(exception.getMessage(), exception); + } + + public SDKException(String message) { + super(message); + } + + public SDKException(String message, Exception exception) { + super(message, exception); + } + + public static SDKException parseFailure(Exception exception) { + throw new SDKException("parse failure", exception); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java index a113dbe..ddeeaac 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java @@ -26,43 +26,44 @@ import ohos.agp.components.Text; * Browse Ability for searching for a bot. */ public class BotSearchAbility extends SearchAbility implements SelectListener { - private int type = 0; - private Text sortSpin; - private Text restrictSpin; - private String[] sortSpinStr = new String[]{ - "connects", - "connects today", - "connects this week", - "connects this month", - "last connect", - "name", - "date", - "size", - "rank", - "wins", - "losses", - "thumbs up", - "thumbs down", - "stars" - }; - private String[] restrictSpinStr = new String[]{ - "", - "forkable", - "has website", - "has subdomain", - "external link", - "Platinum", - "Gold", - "Bronze" - }; - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void onStart(Intent intent) { - super.onStart(intent); + private int type = 0; + private Text sortSpin; + private Text restrictSpin; + private String[] sortSpinStr = new String[]{ + "connects", + "connects today", + "connects this week", + "connects this month", + "last connect", + "name", + "date", + "size", + "rank", + "wins", + "losses", + "thumbs up", + "thumbs down", + "stars" + }; + private String[] restrictSpinStr = new String[]{ + "", + "forkable", + "has website", + "has subdomain", + "external link", + "Platinum", + "Gold", + "Bronze" + }; + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public void onStart(Intent intent) { + super.onStart(intent); // Checkbox checkbox = (Checkbox)findComponentById(ResourceTable.Id_imagesCheckBox); // checkbox.setChecked(MainAbility.showImages); - + // sortSpin = (Text)findComponentById(ResourceTable.Id_sortSpin); // sortSpin.setClickedListener(new Component.ClickedListener() { // @Override @@ -80,9 +81,9 @@ public class BotSearchAbility extends SearchAbility implements SelectListener { // SearchDialogBuilder.with(BotSearchAbility.this,restrictSpinStr).setSelectInterface(BotSearchAbility.this); // } // }); - } - - public String getType() { - return "Bot"; - } + } + + public String getType() { + return "Bot"; + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java deleted file mode 100644 index 6482acb..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java +++ /dev/null @@ -1,33 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability; - -/** - * A convenience enum of different emotional states. - */ - -public enum EmotionalState { - NONE, - LOVE, LIKE, DISLIKE, HATE, - RAGE, ANGER, CALM, SERENE, - ECSTATIC, HAPPY, SAD, CRYING, - PANIC, AFRAID, CONFIDENT, COURAGEOUS, - SURPRISE, BORED, - LAUGHTER, SERIOUS; -} diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index cc2503c..f4b8bd4 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -27,62 +27,62 @@ import ohos.aafwk.content.Operation; */ public abstract class LibreAbility extends Ability { - public void help() { + public void help() { - } + } - /** - * 启动ability - * - * @param ability ability - * @param name name - */ - public void startOpenAbility(Ability ability,String name){ - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - startAbility(intent); - } + /** + * 启动ability + * + * @param ability ability + * @param name name + */ + public void startOpenAbility(Ability ability, String name) { + Intent intent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(ability.getBundleName()) + .withAbilityName(name) + .build(); + intent.setOperation(operation); + startAbility(intent); + } - /** - * 启动ability - * - * @param ability ability - * @param name name - * @param key key - * @param param param - */ - public void startOpenAbility(Ability ability,String name,String key,String param){ - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - intent.setParam(key,param); - startAbility(intent); - } + /** + * 启动ability + * + * @param ability ability + * @param name name + * @param key key + * @param param param + */ + public void startOpenAbility(Ability ability, String name, String key, String param) { + Intent intent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(ability.getBundleName()) + .withAbilityName(name) + .build(); + intent.setOperation(operation); + intent.setParam(key, param); + startAbility(intent); + } - /** - * getIntent - * - * @param ability ability - * @param name name - * @return getIntent - */ - public Intent getIntent(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - return intent; - } + /** + * getIntent + * + * @param ability ability + * @param name name + * @return getIntent + */ + public Intent getIntent(Ability ability, String name) { + Intent intent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(ability.getBundleName()) + .withAbilityName(name) + .build(); + intent.setOperation(operation); + return intent; + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTagAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTagAbility.java index 2e63481..8d77974 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTagAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTagAbility.java @@ -33,7 +33,7 @@ public class ListTagAbility extends LibreAbility { public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_listtag); - flag= (String) intent.getParams().getParam("flag"); + flag = (String) intent.getParams().getParam("flag"); Text title = (Text) findComponentById(ResourceTable.Id_title); if (flag.equals("1")) { title.setText("Select Tags"); diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java index d3e6eba..13c78c5 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java @@ -7,28 +7,29 @@ import org.botlibre.sdk.config.OfflineTemplateConfig; import java.util.ArrayList; import java.util.List; + public class ListTemplateView extends Ability { - final static String listOfBots [] = {"Empty" , "Basic", "Personal Assistance"}; - final static int imagesId [] = {ResourceTable.Media_bot, ResourceTable.Media_bot , ResourceTable.Media_bot}; - final static String listOfDec [] = {"A completely empty template loaded with no knowledge or scripts.", - "A basic bot template with only responses to common greetings and farewells (hello, goodbye, etc.), and the default bootstrap Self language scripts that understand basic language, 'what is' and 'where is' questions, names, dates, math, and topical questions.", - "Template for a Virtual Assistant. This template has command scripts for performing common tasks on such as opening apps, scheduling appointments, and send email."}; + final static String listOfBots[] = {"Empty", "Basic", "Personal Assistance"}; + final static int imagesId[] = {ResourceTable.Media_bot, ResourceTable.Media_bot, ResourceTable.Media_bot}; + final static String listOfDec[] = {"A completely empty template loaded with no knowledge or scripts.", + "A basic bot template with only responses to common greetings and farewells (hello, goodbye, etc.), and the default bootstrap Self language scripts that understand basic language, 'what is' and 'where is' questions, names, dates, math, and topical questions.", + "Template for a Virtual Assistant. This template has command scripts for performing common tasks on such as opening apps, scheduling appointments, and send email."}; - @SuppressWarnings("unchecked") - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_list_view); + @SuppressWarnings("unchecked") + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_list_view); - } + } - public static List retriveTemplates(){ - List items = new ArrayList(); - for (int i = 0; i < listOfBots.length; i++) { - OfflineTemplateConfig item = new OfflineTemplateConfig(imagesId[i],listOfBots[i],listOfDec[i],""+i,i); - items.add(item); - } - return items; - } + public static List retriveTemplates() { + List items = new ArrayList(); + for (int i = 0; i < listOfBots.length; i++) { + OfflineTemplateConfig item = new OfflineTemplateConfig(imagesId[i], listOfBots[i], listOfDec[i], "" + i, i); + items.add(item); + } + return items; + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index 907d776..63303f6 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java @@ -32,47 +32,47 @@ import org.botlibre.sdk.config.UserConfig; */ public class LoginAbility extends LibreAbility implements Component.ClickedListener { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_login); + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_login); - Button connectButton = (Button)findComponentById(ResourceTable.Id_connectButton); - connectButton.setClickedListener(this); - Button signUpButton = (Button)findComponentById(ResourceTable.Id_signUpButton); - signUpButton.setClickedListener(this); - } - - /** - * Start a chat session with the selected instance and the user. - */ - public void connect() { - TextField text = (TextField) findComponentById(ResourceTable.Id_userText); + Button connectButton = (Button) findComponentById(ResourceTable.Id_connectButton); + connectButton.setClickedListener(this); + Button signUpButton = (Button) findComponentById(ResourceTable.Id_signUpButton); + signUpButton.setClickedListener(this); + } + + /** + * Start a chat session with the selected instance and the user. + */ + public void connect() { + TextField text = (TextField) findComponentById(ResourceTable.Id_userText); String user = text.getText().toString().trim(); text = (TextField) findComponentById(ResourceTable.Id_passwordText); String password = text.getText().toString().trim(); - - UserConfig config = new UserConfig(); - config.user = user; - config.password = password; + + UserConfig config = new UserConfig(); + config.user = user; + config.password = password; } - /** - * signUp - */ - public void signUp() { - terminateAbility(); - - startOpenAbility(this,CreateUserAbility.class.getName()); - } + /** + * signUp + */ + public void signUp() { + terminateAbility(); - @Override - public void onClick(Component component) { - if(component.getId() == ResourceTable.Id_connectButton){//登录 - connect(); - } - if(component.getId() == ResourceTable.Id_signUpButton){// 注册 - signUp(); - } - } + startOpenAbility(this, CreateUserAbility.class.getName()); + } + + @Override + public void onClick(Component component) { + if (component.getId() == ResourceTable.Id_connectButton) {//登录 + connect(); + } + if (component.getId() == ResourceTable.Id_signUpButton) {// 注册 + signUp(); + } + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java index bb74658..e6f856a 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java @@ -50,147 +50,147 @@ import java.util.Optional; * Search Ability for searching instances. */ public abstract class SearchAbility extends LibreAbility implements SelectListener { - final static int TAGTEXT = 3,CATTEXT = 4; - - private Image btnTag, btnCat; - - private Text sortSpin,restrictSpin; - private int type = 0; - private RadioButton publicRadio; - private RadioButton radio; - private RadioButton personalRadio; - private BrowseConfig config; - private Button browseButton; - private Button menuButton; - private Text contentRating; - private String[] sortSpinStr = new String[]{ - "connects", - "connects today", - "connects this week", - "connects this month", - "last connect", - "name", - "date", - "size", - "rank", - "wins", - "losses", - "thumbs up", - "thumbs down", - "stars" - }; - private String[] restrictSpinStr = new String[]{ - "", - "forkable", - "has website", - "has subdomain", - "external link", - "Platinum", - "Gold", - "Bronze" - }; - - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void onStart(Intent intent) { - super.onStart(intent); + final static int TAGTEXT = 3, CATTEXT = 4; + + private Image btnTag, btnCat; + + private Text sortSpin, restrictSpin; + private int type = 0; + private RadioButton publicRadio; + private RadioButton radio; + private RadioButton personalRadio; + private BrowseConfig config; + private Button browseButton; + private Button menuButton; + private Text contentRating; + private String[] sortSpinStr = new String[]{ + "connects", + "connects today", + "connects this week", + "connects this month", + "last connect", + "name", + "date", + "size", + "rank", + "wins", + "losses", + "thumbs up", + "thumbs down", + "stars" + }; + private String[] restrictSpinStr = new String[]{ + "", + "forkable", + "has website", + "has subdomain", + "external link", + "Platinum", + "Gold", + "Bronze" + }; + + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public void onStart(Intent intent) { + super.onStart(intent); // setContentView(R.layout.ability_search); - super.setUIContent(ResourceTable.Layout_ability_search); - - btnCat = (Image)findComponentById(ResourceTable.Id_btnCat); - btnTag = (Image)findComponentById(ResourceTable.Id_btnTag); - browseButton = (Button) findComponentById(ResourceTable.Id_browseButton); - menuButton = (Button) findComponentById(ResourceTable.Id_menuButton); - - Checkbox checkbox = (Checkbox) findComponentById(ResourceTable.Id_imagesCheckBox); - StateElement stateElement = new StateElement(); - stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, ResUtils.getPixelMapDrawable(this - , ResourceTable.Media_checkbox_checked)); - stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, ResUtils.getPixelMapDrawable(this - , ResourceTable.Media_checkbox_normal)); - checkbox.setButtonElement(stateElement); - checkbox.setChecked(MainAbility.isShowImages()); - - publicRadio = (RadioButton) findComponentById(ResourceTable.Id_publicRadio); - publicRadio.setChecked(true); - config = new BrowseConfig(); - if (publicRadio.isChecked()) { - config.typeFilter = "Public"; - } - config.typeFilter = "Public"; - radio = (RadioButton) findComponentById(ResourceTable.Id_privateRadio); - if (radio.isChecked()) { - config.typeFilter = "Private"; - } - personalRadio = (RadioButton) findComponentById(ResourceTable.Id_personalRadio); - if (radio.isChecked()) { - config.typeFilter = "Personal"; - } - - publicRadio.setButtonElement(setSelect()); - radio.setButtonElement(setSelect()); - personalRadio.setButtonElement(setSelect()); - publicRadio.setClickedListener(sampleOnClickListener); - radio.setClickedListener(sampleOnClickListener); - personalRadio.setClickedListener(sampleOnClickListener); - - Text title = (Text) findComponentById(ResourceTable.Id_title); - title.setText("Search " + getType() + "s"); - sortSpin = (Text)findComponentById(ResourceTable.Id_sortSpin); - sortSpin.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - type = 0; - SearchDialogBuilder.with(SearchAbility.this,sortSpinStr).setSelectInterface(SearchAbility.this); - } - }); - - restrictSpin = (Text) findComponentById(ResourceTable.Id_restrictSpin); - restrictSpin.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - type = 1; - SearchDialogBuilder.with(SearchAbility.this,restrictSpinStr).setSelectInterface(SearchAbility.this); - } - }); - - - contentRating = (Text) findComponentById(ResourceTable.Id_ContentRatingSpin); - - contentRating.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - type = 2; - SearchDialogBuilder.with(SearchAbility.this,MainAbility.getContentRatings()).setSelectInterface(SearchAbility.this); - } - }); - - browseButton.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - browse(); - } - }); - - menuButton.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - menu(); - } - }); - btnTag.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - startOpenAbility(SearchAbility.this,ListTagAbility.class.getName(),"flag","1"); - } - }); - btnCat.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - startOpenAbility(SearchAbility.this,ListTagAbility.class.getName(),"flag","2"); - } - }); + super.setUIContent(ResourceTable.Layout_ability_search); + + btnCat = (Image) findComponentById(ResourceTable.Id_btnCat); + btnTag = (Image) findComponentById(ResourceTable.Id_btnTag); + browseButton = (Button) findComponentById(ResourceTable.Id_browseButton); + menuButton = (Button) findComponentById(ResourceTable.Id_menuButton); + + Checkbox checkbox = (Checkbox) findComponentById(ResourceTable.Id_imagesCheckBox); + StateElement stateElement = new StateElement(); + stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, ResUtils.getPixelMapDrawable(this + , ResourceTable.Media_checkbox_checked)); + stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, ResUtils.getPixelMapDrawable(this + , ResourceTable.Media_checkbox_normal)); + checkbox.setButtonElement(stateElement); + checkbox.setChecked(MainAbility.isShowImages()); + + publicRadio = (RadioButton) findComponentById(ResourceTable.Id_publicRadio); + publicRadio.setChecked(true); + config = new BrowseConfig(); + if (publicRadio.isChecked()) { + config.typeFilter = "Public"; + } + config.typeFilter = "Public"; + radio = (RadioButton) findComponentById(ResourceTable.Id_privateRadio); + if (radio.isChecked()) { + config.typeFilter = "Private"; + } + personalRadio = (RadioButton) findComponentById(ResourceTable.Id_personalRadio); + if (radio.isChecked()) { + config.typeFilter = "Personal"; + } + + publicRadio.setButtonElement(setSelect()); + radio.setButtonElement(setSelect()); + personalRadio.setButtonElement(setSelect()); + publicRadio.setClickedListener(sampleOnClickListener); + radio.setClickedListener(sampleOnClickListener); + personalRadio.setClickedListener(sampleOnClickListener); + + Text title = (Text) findComponentById(ResourceTable.Id_title); + title.setText("Search " + getType() + "s"); + sortSpin = (Text) findComponentById(ResourceTable.Id_sortSpin); + sortSpin.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + type = 0; + SearchDialogBuilder.with(SearchAbility.this, sortSpinStr).setSelectInterface(SearchAbility.this); + } + }); + + restrictSpin = (Text) findComponentById(ResourceTable.Id_restrictSpin); + restrictSpin.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + type = 1; + SearchDialogBuilder.with(SearchAbility.this, restrictSpinStr).setSelectInterface(SearchAbility.this); + } + }); + + + contentRating = (Text) findComponentById(ResourceTable.Id_ContentRatingSpin); + + contentRating.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + type = 2; + SearchDialogBuilder.with(SearchAbility.this, MainAbility.getContentRatings()).setSelectInterface(SearchAbility.this); + } + }); + + browseButton.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + browse(); + } + }); + + menuButton.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + menu(); + } + }); + btnTag.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + startOpenAbility(SearchAbility.this, ListTagAbility.class.getName(), "flag", "1"); + } + }); + btnCat.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + startOpenAbility(SearchAbility.this, ListTagAbility.class.getName(), "flag", "2"); + } + }); // btnTag.setOnClickListener(new View.OnClickListener() { // @@ -217,7 +217,7 @@ public abstract class SearchAbility extends LibreAbility implements SelectListen // action = new HttpGetCategoriesAction(this, getType()); // action.execute(); // MainAbility.searching = !MainAbility.browsing; - } + } // @Override // protected void onResume() { @@ -228,32 +228,32 @@ public abstract class SearchAbility extends LibreAbility implements SelectListen // super.onResume(); // } - //Getting Info from the Opened Activities - @Override - protected void onAbilityResult(int requestCode, int resultCode, Intent data) { - // TODO Auto-generated method stub - super.onAbilityResult(requestCode, resultCode, data); - switch(requestCode){ - case TAGTEXT: + //Getting Info from the Opened Activities + @Override + protected void onAbilityResult(int requestCode, int resultCode, Intent data) { + // TODO Auto-generated method stub + super.onAbilityResult(requestCode, resultCode, data); + switch (requestCode) { + case TAGTEXT: // if(resultCode == RESULT_OK){ // tagsText.setText(tagsText.getText()+data.getStringParam("tag") + ", "); //as Tags // } - break; - case CATTEXT: + break; + case CATTEXT: // if(resultCode == RESULT_OK){ // categoriesText.setText(categoriesText.getText()+data.getStringParam("cat") + ", ");//as Categories // } - break; - } - } - - + break; + } + } + + // public void onDestroy() { // super.onDestroy(); // MainAbility.searching = false; // } - public void browse() { + public void browse() { // Spinner sortSpin = (Spinner)findComponentById(ResourceTable.Id_sortSpin); // config.sort = (String)sortSpin.getSelectedItem(); // Spinner restrictSpin = (Spinner)findComponentById(ResourceTable.Id_restrictSpin); @@ -262,110 +262,111 @@ public abstract class SearchAbility extends LibreAbility implements SelectListen // Spinner contentRating = (Spinner) findComponentById(ResourceTable.Id_ContentRatingSpin); // MainAbility.contentRating = (String) contentRating.getSelectedItem(); // config.contentRating = MainAbility.contentRating; - //save contentRating - Preferences editor = PreferencesUtils.getPreferences(MainAbility.getCurrent()); - editor.putString("contentRating", MainAbility.getContentRating()); - editor.flushSync(); - - TextField tagText = (TextField)findComponentById(ResourceTable.Id_tagsText); - config.tag = (String)tagText.getText().toString(); - TextField categoryText = (TextField)findComponentById(ResourceTable.Id_categoriesText); - config.category = (String)categoryText.getText().toString(); - TextField filterEdit = (TextField)findComponentById(ResourceTable.Id_filterText); - config.filter = filterEdit.getText().toString(); - Checkbox checkbox = (Checkbox)findComponentById(ResourceTable.Id_imagesCheckBox); - MainAbility.setShowImages(checkbox.isChecked()); - - config.type = getType(); - - } - public StateElement setSelect() { - StateElement stateElement = new StateElement(); - stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, - ResUtils.getPixelMapDrawable(getContext(), ResourceTable.Media_radioselect)); - stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, - ResUtils.getPixelMapDrawable(getContext(), ResourceTable.Media_radionormal)); - - return stateElement; - } - private final Component.ClickedListener sampleOnClickListener = new RadioButton.ClickedListener() { - @Override - public void onClick(Component component) { - if (publicRadio.isChecked()) { - config.typeFilter = "Public"; - } else if (radio.isChecked()) { - config.typeFilter = "Private"; - } else if (personalRadio.isChecked()) { - config.typeFilter = "Personal"; - } - } - }; - - public abstract String getType(); - - public void menu() { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(this); - DisplayAttributes displayAttributes = display.get().getAttributes(); - - PopupDialog menuDialog = new PopupDialog(this, null); - DirectionalLayout menuComponent = (DirectionalLayout) LayoutScatter.getInstance(this) - .parse(ResourceTable.Layout_search_menu, null, false); - menuDialog.setCustomComponent(menuComponent); - menuDialog.showOnCertainPosition(1,displayAttributes.width,-displayAttributes.width + 150); - menuDialog.setAutoClosable(true); - menuDialog.setAlignment(LayoutAlignment.RIGHT|LayoutAlignment.TOP); - menuDialog.show(); - - Text mybots = (Text) menuComponent.findComponentById(ResourceTable.Id_mybots); - mybots.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { + //save contentRating + Preferences editor = PreferencesUtils.getPreferences(MainAbility.getCurrent()); + editor.putString("contentRating", MainAbility.getContentRating()); + editor.flushSync(); + + TextField tagText = (TextField) findComponentById(ResourceTable.Id_tagsText); + config.tag = (String) tagText.getText().toString(); + TextField categoryText = (TextField) findComponentById(ResourceTable.Id_categoriesText); + config.category = (String) categoryText.getText().toString(); + TextField filterEdit = (TextField) findComponentById(ResourceTable.Id_filterText); + config.filter = filterEdit.getText().toString(); + Checkbox checkbox = (Checkbox) findComponentById(ResourceTable.Id_imagesCheckBox); + MainAbility.setShowImages(checkbox.isChecked()); + + config.type = getType(); + + } + + public StateElement setSelect() { + StateElement stateElement = new StateElement(); + stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, + ResUtils.getPixelMapDrawable(getContext(), ResourceTable.Media_radioselect)); + stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, + ResUtils.getPixelMapDrawable(getContext(), ResourceTable.Media_radionormal)); + + return stateElement; + } + + private final Component.ClickedListener sampleOnClickListener = new RadioButton.ClickedListener() { + @Override + public void onClick(Component component) { + if (publicRadio.isChecked()) { + config.typeFilter = "Public"; + } else if (radio.isChecked()) { + config.typeFilter = "Private"; + } else if (personalRadio.isChecked()) { + config.typeFilter = "Personal"; + } + } + }; + + public abstract String getType(); + + public void menu() { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(this); + DisplayAttributes displayAttributes = display.get().getAttributes(); + + PopupDialog menuDialog = new PopupDialog(this, null); + DirectionalLayout menuComponent = (DirectionalLayout) LayoutScatter.getInstance(this) + .parse(ResourceTable.Layout_search_menu, null, false); + menuDialog.setCustomComponent(menuComponent); + menuDialog.showOnCertainPosition(1, displayAttributes.width, -displayAttributes.width + 150); + menuDialog.setAutoClosable(true); + menuDialog.setAlignment(LayoutAlignment.RIGHT | LayoutAlignment.TOP); + menuDialog.show(); + + Text mybots = (Text) menuComponent.findComponentById(ResourceTable.Id_mybots); + mybots.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { // browseMyBots(); // menuDialog.destroy(); - } - }); - - Text browsefeatured = (Text) menuComponent.findComponentById(ResourceTable.Id_browsefeatured); - browsefeatured.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - browseFeatured(); - menuDialog.destroy(); - } - }); - - Text browsecategories = (Text) menuComponent.findComponentById(ResourceTable.Id_browsecategories); - browsecategories.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - //browseCategories(); - menuDialog.destroy(); - } - }); - } - - - - public void browseFeatured() { - BrowseConfig config = new BrowseConfig(); - config.type = getType(); - config.typeFilter = "Featured"; - config.contentRating = MainAbility.getContentRating(); - } - - @Override - public void selectItem(String select) { - if(type == 0){ - sortSpin.setText(select); - config.sort = select; - } else if(type == 1){ - restrictSpin.setText(select); - config.restrict = select; - } else if(type == 2){ - contentRating.setText(select); - config.contentRating = select; - } - - } + } + }); + + Text browsefeatured = (Text) menuComponent.findComponentById(ResourceTable.Id_browsefeatured); + browsefeatured.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + browseFeatured(); + menuDialog.destroy(); + } + }); + + Text browsecategories = (Text) menuComponent.findComponentById(ResourceTable.Id_browsecategories); + browsecategories.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + //browseCategories(); + menuDialog.destroy(); + } + }); + } + + + public void browseFeatured() { + BrowseConfig config = new BrowseConfig(); + config.type = getType(); + config.typeFilter = "Featured"; + config.contentRating = MainAbility.getContentRating(); + } + + @Override + public void selectItem(String select) { + if (type == 0) { + sortSpin.setText(select); + config.sort = select; + } else if (type == 1) { + restrictSpin.setText(select); + config.restrict = select; + } else if (type == 2) { + contentRating.setText(select); + config.contentRating = select; + } + + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java index e6b912b..edc0ece 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java @@ -26,45 +26,45 @@ import ohos.aafwk.ability.Ability; public class HttpChatAction extends HttpAction { - ChatConfig config; + ChatConfig config; - public HttpChatAction(Ability ability, ChatConfig config) { - super(ability); - this.config = config; - } + public HttpChatAction(Ability ability, ChatConfig config) { + super(ability); + this.config = config; + } - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().chat(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPreExecute() { - if (!this.config.disconnect) { - super.onPreExecute(); - } - } + @Override + protected String doInBackground(Void... params) { + try { + MainAbility.getConnection().chat(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } - @Override - protected void onPostExecute(String xml) { - if (this.config.disconnect) { - return; - } - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.errorInfo(1,this.exception.getMessage(), this.exception, this.ability); - return; - } - try { - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } + @Override + protected void onPreExecute() { + if (!this.config.disconnect) { + super.onPreExecute(); + } + } + + @Override + protected void onPostExecute(String xml) { + if (this.config.disconnect) { + return; + } + super.onPostExecute(xml); + if (this.exception != null) { + MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); + return; + } + try { + } catch (Exception error) { + this.exception = error; + MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + return; + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java index 36a291a..cdc427f 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java @@ -36,7 +36,7 @@ public class HttpConnectAction extends HttpUIResultAction { doInBackground(); } -// @Override + // @Override public void doInBackground() { loadingDialog(); try { @@ -48,7 +48,7 @@ public class HttpConnectAction extends HttpUIResultAction { onPostExecute(); } -// @Override + // @Override protected void onPostExecute() { // super.onPostExecute(xml); if (this.exception != null) { @@ -74,7 +74,7 @@ public class HttpConnectAction extends HttpUIResultAction { this.exception = error; MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - Preferences cookies=PreferencesUtils.getPreferences(this.ability); + Preferences cookies = PreferencesUtils.getPreferences(this.ability); cookies.putString("user", null); cookies.putString("token", null); cookies.flushSync(); diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java index 084535d..f0212cf 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java @@ -25,54 +25,54 @@ import ohos.aafwk.ability.Ability; import ohos.data.preferences.Preferences; public class HttpCreateAction extends HttpUIAction { - - WebMediumConfig config; - boolean finish; - public HttpCreateAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - this.finish = true; - } - - public HttpCreateAction(Ability ability, WebMediumConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - } + WebMediumConfig config; + boolean finish; - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.getConnection().create(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + public HttpCreateAction(Ability ability, WebMediumConfig config) { + super(ability); + this.config = config; + this.finish = true; + } - @SuppressWarnings("rawtypes") - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.setInstance(this.config); - - if (this.finish) { - this.ability.terminateAbility(); - } + public HttpCreateAction(Ability ability, WebMediumConfig config, boolean finish) { + super(ability); + this.config = config; + this.finish = finish; + } - Preferences cookies= PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), this.config.name); - cookies.flushSync(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } + @Override + protected String doInBackground(Void... params) { + try { + this.config = MainAbility.getConnection().create(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } + + @SuppressWarnings("rawtypes") + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + try { + MainAbility.setInstance(this.config); + + if (this.finish) { + this.ability.terminateAbility(); + } + + Preferences cookies = PreferencesUtils.getPreferences(this.ability); + cookies.putString(this.config.getType(), this.config.name); + cookies.flushSync(); + } catch (Exception error) { + this.exception = error; + MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + return; + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java index 2c87b7e..0211740 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java @@ -19,46 +19,45 @@ package org.botlibre.sdk.ability.actions; - import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.ability.Ability; import ohos.app.Context; public class HttpCreateUserAction extends HttpUIResultAction { - UserConfig config; - - public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { - super(ability); - this.config = config; - doInBackground(); - } + UserConfig config; - protected void doInBackground() { - try { - this.config = MainAbility.getConnection().create(ability,this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } + public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { + super(ability); + this.config = config; + doInBackground(); + } - if (this.exception != null) { - return; - } - try { - MainAbility.setUser(this.config); - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - removeDialog(); - return; - } + protected void doInBackground() { + try { + this.config = MainAbility.getConnection().create(ability, this.config); + } catch (Exception exception) { + this.exception = exception; + removeDialog(); + return; + } + + if (this.exception != null) { + return; + } + try { + MainAbility.setUser(this.config); + this.ability.terminateAbility(); + } catch (Exception error) { + this.exception = error; + removeDialog(); + return; + } - } + } -// @Override - public void onPostExecute(String xml) { + // @Override + public void onPostExecute(String xml) { // super.onPostExecute(xml); } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java index f3e80d6..ab2e355 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java @@ -21,36 +21,37 @@ package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.AvatarConfig; import ohos.aafwk.ability.Ability; + public class HttpFetchChatAvatarAction extends HttpUIAction { - AvatarConfig config; + AvatarConfig config; + + public HttpFetchChatAvatarAction(Ability ability, AvatarConfig config) { + super(ability); + this.config = config; + } - public HttpFetchChatAvatarAction(Ability ability, AvatarConfig config) { - super(ability); - this.config = config; - } + @Override + protected String doInBackground(Void... params) { + try { + this.config = MainAbility.getConnection().fetch(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.getConnection().fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + try { + } catch (Exception error) { + this.exception = error; + MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + return; + } + } - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java deleted file mode 100644 index 60e055f..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; -public class HttpFetchOrCreateAction extends HttpFetchAction { - - public HttpFetchOrCreateAction(Ability ability, WebMediumConfig config, boolean launch) { - super(ability, config, launch); - } - -// @Override - public void onPostExecute(String xml) { - if (this.exception != null) { - InstanceConfig instance = new InstanceConfig(); - instance.name = config.name; - instance.isPrivate = true; - instance.template = "template"; - - instance.categories = "Misc"; - instance.tags = ""; - - HttpCreateAction action = new HttpCreateAction(ability, instance); - action.execute(); - } else { -// super.onPostExecute(xml); - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java index 26381dc..d76319b 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java @@ -20,17 +20,18 @@ package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.config.WebMediumConfig; import ohos.aafwk.ability.Ability; + public class HttpFetchWarAction extends HttpFetchAction { - public HttpFetchWarAction(Ability ability, WebMediumConfig config) { - super(ability, config); - } + public HttpFetchWarAction(Ability ability, WebMediumConfig config) { + super(ability, config); + } -// @Override - public void onPostExecute(String xml) { + // @Override + public void onPostExecute(String xml) { // super.superOnPostExecute(xml); // StartWarAbility.bot1 = (InstanceConfig)this.config; // ((StartWarAbility)this.ability).resetView(); - } - + } + } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java index 57525bd..d24138a 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java @@ -23,29 +23,29 @@ import org.botlibre.sdk.config.IssueConfig; import ohos.aafwk.ability.Ability; public class HttpFlagIssueAction extends HttpUIAction { - IssueConfig config; + IssueConfig config; - public HttpFlagIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } + public HttpFlagIssueAction(Ability ability, IssueConfig config) { + super(ability); + this.config = config; + } - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + protected String doInBackground(Void... params) { + try { + MainAbility.getConnection().flag(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.getIssue().isFlagged = true; - } + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + MainAbility.getIssue().isFlagged = true; + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java index 79884ce..9f857eb 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java @@ -21,30 +21,31 @@ package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.ability.Ability; + public class HttpFlagUserAction extends HttpUIAction { - UserConfig config; + UserConfig config; + + public HttpFlagUserAction(Ability ability, UserConfig config) { + super(ability); + this.config = config; + } - public HttpFlagUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - } + @Override + protected String doInBackground(Void... params) { + try { + MainAbility.getConnection().flag(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + } - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java index 9efe353..2739885 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java @@ -27,9 +27,9 @@ import java.util.List; public class HttpGetInstancesAction extends HttpUIResultAction { - BrowseConfig config; - List instances; - boolean finish = false; + BrowseConfig config; + List instances; + boolean finish = false; public HttpGetInstancesAction(Ability ability, BrowseConfig config) { super(ability); @@ -50,10 +50,10 @@ public class HttpGetInstancesAction extends HttpUIResultAction { this.finish = finish; } - public void doInBackground(){ + public void doInBackground() { loadingDialog(); try { - this.instances = MainAbility.getConnection().browse(ability,config); + this.instances = MainAbility.getConnection().browse(ability, config); } catch (Exception exception) { this.exception = exception; removeDialog(); @@ -68,7 +68,7 @@ public class HttpGetInstancesAction extends HttpUIResultAction { // return ""; // } -// @Override + // @Override public void onPostExecute() { // super.onPostExecute(xml); if (this.exception != null) { diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java index 7b9ca7d..eea8b9f 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java @@ -28,44 +28,44 @@ import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; public class HttpGetPostsAction extends HttpUIAction { - BrowseConfig config; - List posts; - boolean finish = false; + BrowseConfig config; + List posts; + boolean finish = false; - public HttpGetPostsAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } + public HttpGetPostsAction(Ability Ability, BrowseConfig config) { + super(Ability); + this.config = config; + } - public HttpGetPostsAction(Ability Ability, BrowseConfig config, boolean finish) { - super(Ability); - this.config = config; - this.finish = finish; - } + public HttpGetPostsAction(Ability Ability, BrowseConfig config, boolean finish) { + super(Ability); + this.config = config; + this.finish = finish; + } - @Override - protected String doInBackground(Void... params) { - try { - this.posts = MainAbility.getConnection().getPosts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + protected String doInBackground(Void... params) { + try { + this.posts = MainAbility.getConnection().getPosts(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setPosts(this.posts); - - if (this.finish) { - this.ability.terminateAbility(); - } - MainAbility.setBrowsePosts(this.config); + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + MainAbility.setPosts(this.posts); + + if (this.finish) { + this.ability.terminateAbility(); + } + MainAbility.setBrowsePosts(this.config); Intent intent = new Intent(); this.ability.startAbility(intent); - } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java index c19fac4..88568b1 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java @@ -22,7 +22,7 @@ import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; -public abstract class HttpResultAction{ +public abstract class HttpResultAction { protected Ability ability; protected Exception exception; @@ -42,7 +42,7 @@ public abstract class HttpResultAction{ * 启动ability * * @param ability ability - * @param name name + * @param name name */ public void startOpenAbility(Ability ability, String name) { Intent intent = new Intent(); @@ -58,8 +58,8 @@ public abstract class HttpResultAction{ /** * 启动ability * - * @param ability ability - * @param name name + * @param ability ability + * @param name name * @param requestCode requestCode */ public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java index a8a52bb..43ef52f 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java @@ -32,41 +32,41 @@ import ohos.agp.window.service.DisplayManager; import java.util.Optional; public abstract class HttpUIAction extends HttpAction { - protected CommonDialog dialog; + protected CommonDialog dialog; - public HttpUIAction(Ability Ability) { - super(Ability); - } + public HttpUIAction(Ability Ability) { + super(Ability); + } - // 加载 - public void loadingDialog(){ - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } + // 加载 + public void loadingDialog() { + try { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); + DisplayAttributes displayAttributes = display.get().getAttributes(); + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). + parse(ResourceTable.Layout_loading_dialog, + null, false); + this.dialog = new CommonDialog(this.ability); + this.dialog.setContentCustomComponent(layout); + this.dialog.setAutoClosable(false); + this.dialog.setSize(displayAttributes.width - 100, 150); + this.dialog.show(); + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); + } + } - public void removeDialog(){ - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1,this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } + public void removeDialog() { + try { + if (this.dialog != null) { + this.dialog.destroy(); + } + if (this.exception != null) { + MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); + } + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java index c952ff7..b79ac22 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java @@ -33,45 +33,41 @@ import ohos.agp.window.service.DisplayManager; import java.util.Optional; public abstract class HttpUIResultAction extends HttpResultAction { - protected CommonDialog dialog; + protected CommonDialog dialog; - public HttpUIResultAction(Ability Ability) { - super(Ability); - } + public HttpUIResultAction(Ability Ability) { + super(Ability); + } - // 加载 - public void loadingDialog(){ - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } + // 加载 + public void loadingDialog() { + try { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); + DisplayAttributes displayAttributes = display.get().getAttributes(); + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). + parse(ResourceTable.Layout_loading_dialog, + null, false); + this.dialog = new CommonDialog(this.ability); + this.dialog.setContentCustomComponent(layout); + this.dialog.setAutoClosable(false); + this.dialog.setSize(displayAttributes.width - 100, 150); + this.dialog.show(); + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); + } + } - public void removeDialog(){ - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { -// if(!exception.toString().equals("403")) { -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// } else { - MainAbility.errorInfo(1,ResUtils.getString(ability,ResourceTable.String_exception), this.exception, this.ability); -// } - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } + public void removeDialog() { + try { + if (this.dialog != null) { + this.dialog.destroy(); + } + if (this.exception != null) { + MainAbility.errorInfo(1, ResUtils.getString(ability, ResourceTable.String_exception), this.exception, this.ability); + } + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java index 89f91d0..2e498d3 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java @@ -31,29 +31,29 @@ import ohos.data.preferences.Preferences; import java.util.ArrayList; /** - * used for selecting an offline avatar. + * used for selecting an offline avatar. */ public class AvatarSelection extends Ability { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_list_view); - final int [] imges = {}; - final String [] names = {}; - ((Text) findComponentById(ResourceTable.Id_theTitle)).setText("Select Avatar"); - ArrayList items = new ArrayList(); - for (int i = 0; i < names.length; i++) { - items.add(new OfflineTemplateConfig(imges[i],names[i],null,null)); - } - - } - - public static void saveSelectedAvatar(String nameOfAvatar) { - MainAbility.setNameOfAvatar(nameOfAvatar); - Preferences cookies = PreferencesUtils.getPreferences(MainAbility.getCurrent()); - cookies.putString("nameOfAvatar", nameOfAvatar); - cookies.flushSync(); - } + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_list_view); + final int[] imges = {}; + final String[] names = {}; + ((Text) findComponentById(ResourceTable.Id_theTitle)).setText("Select Avatar"); + ArrayList items = new ArrayList(); + for (int i = 0; i < names.length; i++) { + items.add(new OfflineTemplateConfig(imges[i], names[i], null, null)); + } + + } + + public static void saveSelectedAvatar(String nameOfAvatar) { + MainAbility.setNameOfAvatar(nameOfAvatar); + Preferences cookies = PreferencesUtils.getPreferences(MainAbility.getCurrent()); + cookies.putString("nameOfAvatar", nameOfAvatar); + cookies.flushSync(); + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java index 3523cf2..a77ff1c 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java @@ -23,10 +23,10 @@ package org.botlibre.sdk.ability.listener; * This gives asynchronous notification when a channel receives a message, or notice. */ public interface LanguageListener { - /** - * A user message was received from the channel. - * - * @param select select - */ - void selectLanguageItem(String select); + /** + * A user message was received from the channel. + * + * @param select select + */ + void selectLanguageItem(String select); } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java index 60077f9..75e5450 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java @@ -23,10 +23,10 @@ package org.botlibre.sdk.ability.listener; * This gives asynchronous notification when a channel receives a message, or notice. */ public interface SelectListener { - /** - * A user message was received from the channel. - * - * @param select select - */ - void selectItem(String select); + /** + * A user message was received from the channel. + * + * @param select select + */ + void selectItem(String select); } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java index 7d0c9ee..f6a3c42 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java @@ -8,37 +8,37 @@ import java.io.StringWriter; * DTO for XML chat war config. */ public class ChatWarConfig extends Config { - public String winner; - public String looser; - public String topic; - public String secret; - - public ChatWarConfig() { - - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String winner; + public String looser; + public String topic; + public String secret; + + public ChatWarConfig() { + + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java index 11be68b..2f0b255 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java @@ -6,32 +6,32 @@ import org.botlibre.sdk.config.InstanceConfig; import ohos.aafwk.ability.Ability; public class HttpChatWarAction extends HttpUIAction { - ChatWarConfig config; - InstanceConfig instance; + ChatWarConfig config; + InstanceConfig instance; - public HttpChatWarAction(Ability ability, ChatWarConfig config) { - super(ability); - this.config = config; - } + public HttpChatWarAction(Ability ability, ChatWarConfig config) { + super(ability); + this.config = config; + } - @Override - protected String doInBackground(Void... params) { - try { - InstanceConfig instance = new InstanceConfig(); - this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + protected String doInBackground(Void... params) { + try { + InstanceConfig instance = new InstanceConfig(); + this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } + + @Override + protected void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + MainAbility.setInstance(this.instance); + } - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setInstance(this.instance); - } - } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java index a0caaf3..53f3fbf 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java @@ -120,7 +120,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi MainAbility.showMessage("Please enter a topic", this); return; } - MainAbility.setInstance( bot1); + MainAbility.setInstance(bot1); MainAbility.getConnection().setUser(null); } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java index 6ee4b1e..53158b9 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java @@ -11,102 +11,107 @@ import org.w3c.dom.Element; * The media is the short URL to the media file on the server. */ public class AvatarMedia extends Config { - public String mediaId; - public String name; - public String types; - public String media; - public String emotions; - public String actions; - public String poses; - public boolean hd; - public boolean talking; - - public void parseXML(Element element) { - super.parseXML(element); - - this.mediaId = element.getAttribute("mediaId"); - this.name = element.getAttribute("name"); - this.types = element.getAttribute("type"); - this.media = element.getAttribute("media"); - this.emotions = element.getAttribute("emotions"); - this.actions = element.getAttribute("actions"); - this.poses = element.getAttribute("poses"); - this.hd = Boolean.valueOf(element.getAttribute("hd")); - this.talking = Boolean.valueOf(element.getAttribute("talking")); - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public boolean getHD() { - return hd; - } - public boolean isImage() { - return this.types.contains("image") || this.type.isEmpty(); - } - - public boolean isVideo() { - return this.types != null && this.type.indexOf("video") != -1; - } - - public boolean isAudio() { - return this.types != null && this.type.indexOf("audio") != -1; - } - public String getType() { - return types; - } - public String getEmotions() { - return emotions; - } - - public void setEmotions(String emotions) { - this.emotions = emotions; - } - public String getActions() { - return actions; - } - - public String getPoses() { - return poses; - } - - public void setPoses(String poses) { - this.poses = poses; - } - - public void setActions(String actions) { - this.actions = actions; - } - public boolean getTalking() { - return talking; - } - - public void setTalking(boolean talking) { - this.talking = talking; - } + public String mediaId; + public String name; + public String types; + public String media; + public String emotions; + public String actions; + public String poses; + public boolean hd; + public boolean talking; + + public void parseXML(Element element) { + super.parseXML(element); + + this.mediaId = element.getAttribute("mediaId"); + this.name = element.getAttribute("name"); + this.types = element.getAttribute("type"); + this.media = element.getAttribute("media"); + this.emotions = element.getAttribute("emotions"); + this.actions = element.getAttribute("actions"); + this.poses = element.getAttribute("poses"); + this.hd = Boolean.valueOf(element.getAttribute("hd")); + this.talking = Boolean.valueOf(element.getAttribute("talking")); + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public boolean getHD() { + return hd; + } + + public boolean isImage() { + return this.types.contains("image") || this.type.isEmpty(); + } + + public boolean isVideo() { + return this.types != null && this.type.indexOf("video") != -1; + } + + public boolean isAudio() { + return this.types != null && this.type.indexOf("audio") != -1; + } + + public String getType() { + return types; + } + + public String getEmotions() { + return emotions; + } + + public void setEmotions(String emotions) { + this.emotions = emotions; + } + + public String getActions() { + return actions; + } + + public String getPoses() { + return poses; + } + + public void setPoses(String poses) { + this.poses = poses; + } + + public void setActions(String actions) { + this.actions = actions; + } + + public boolean getTalking() { + return talking; + } + + public void setTalking(boolean talking) { + this.talking = talking; + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java deleted file mode 100644 index e947ee2..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java +++ /dev/null @@ -1,80 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import org.botlibre.sdk.util.Utils; - -import java.io.StringWriter; - - -/** - * An avatar message can be used to have an avatar speak a message. - * The avatar message gives the avatar the text to speak, and returns a ChatResponse that includes the text-to-speech and video animation. - * This object can be converted to and from XML for usage with the web API. - */ -public class AvatarMessage extends Config { - public String message; - public String avatar; - public String emote; - public String action; - public String pose; - public boolean speak; - public String voice; - public String format; - public boolean hd; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java deleted file mode 100644 index 5e672e1..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -import org.w3c.dom.Element; - - -/** - * DTO for XML bot mode config. - */ -public class BotModeConfig extends Config { - - public String mode; - public String bot; - - public void parseXML(Element element) { - super.parseXML(element); - - this.mode = element.getAttribute("mode"); - this.bot = element.getAttribute("bot"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java index e108292..d0c83b1 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java @@ -6,50 +6,50 @@ import java.io.StringWriter; * DTO for XML browse options. */ public class BrowseConfig extends Config { - public String types; - public String typeFilter; - public String category; - public String tag; - public String filter; - public String userFilter; - public String sort; - public String restrict; - public String page; - public String contentRating; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String types; + public String typeFilter; + public String category; + public String tag; + public String filter; + public String userFilter; + public String sort; + public String restrict; + public String page; + public String contentRating; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java index 0fceac1..a729c10 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java @@ -8,53 +8,53 @@ import org.w3c.dom.Element; * DTO for XML channel config. */ public class ChannelConfig extends WebMediumConfig { - public String types; - public String videoAccessMode; - public String audioAccessMode; - public String messages; - public String usersOnline; - public String adminsOnline; - - @Override - public String getType() { - return "channel"; - } - - @Override - public String stats() { - return this.usersOnline + " users online, " + this.adminsOnline + " admins"; - } - - public WebMediumConfig credentials() { - ChannelConfig config = new ChannelConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.type = element.getAttribute("type"); - this.videoAccessMode = element.getAttribute("videoAccessMode"); - this.audioAccessMode = element.getAttribute("audioAccessMode"); - this.messages = element.getAttribute("messages"); - this.usersOnline = element.getAttribute("usersOnline"); - this.adminsOnline = element.getAttribute("adminsOnline"); - } + public String types; + public String videoAccessMode; + public String audioAccessMode; + public String messages; + public String usersOnline; + public String adminsOnline; + + @Override + public String getType() { + return "channel"; + } + + @Override + public String stats() { + return this.usersOnline + " users online, " + this.adminsOnline + " admins"; + } + + public WebMediumConfig credentials() { + ChannelConfig config = new ChannelConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.type = element.getAttribute("type"); + this.videoAccessMode = element.getAttribute("videoAccessMode"); + this.audioAccessMode = element.getAttribute("audioAccessMode"); + this.messages = element.getAttribute("messages"); + this.usersOnline = element.getAttribute("usersOnline"); + this.adminsOnline = element.getAttribute("adminsOnline"); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java index c2ce860..fec4518 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java @@ -27,73 +27,73 @@ import java.io.StringWriter; /** * DTO for XML chat config. */ -public class ChatConfig extends Config { - public String conversation; - public boolean correction; - public boolean offensive; - public boolean disconnect; - public String emote; - public String action; - public String message; - public boolean speak; - public boolean includeQuestion; - public boolean avatarHD; - public String avatarFormat; - public String avatar; - public String language; - public String voice; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } +public class ChatConfig extends Config { + public String conversation; + public boolean correction; + public boolean offensive; + public boolean disconnect; + public String emote; + public String action; + public String message; + public boolean speak; + public boolean includeQuestion; + public boolean avatarHD; + public String avatarFormat; + public String avatar; + public String language; + public String voice; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.message != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.message)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java index 9e93cab..d47f7e6 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java @@ -26,81 +26,81 @@ import org.w3c.dom.Node; /** * DTO for XML chat config. */ -public class ChatResponse extends Config { - public String conversation; - public String message; - public String question; - public String emote; - public String action; - public String pose; - public String command; - public String avatar; - public String avatar2; - public String avatar3; - public String avatar4; - public String avatar5; - public String avatarType; - public String avatarTalk; - public String avatarTalkType; - public String avatarAction; - public String avatarActionType; - public String avatarActionAudio; - public String avatarActionAudioType; - public String avatarAudio; - public String avatarAudioType; - public String avatarBackground; - public String speech; - - public boolean isVideo() { - return this.avatarType != null && this.avatarType.indexOf("video") != -1; - } - - public boolean isVideoTalk() { - return this.avatarTalkType != null && this.avatarTalkType.indexOf("video") != -1; - } +public class ChatResponse extends Config { + public String conversation; + public String message; + public String question; + public String emote; + public String action; + public String pose; + public String command; + public String avatar; + public String avatar2; + public String avatar3; + public String avatar4; + public String avatar5; + public String avatarType; + public String avatarTalk; + public String avatarTalkType; + public String avatarAction; + public String avatarActionType; + public String avatarActionAudio; + public String avatarActionAudioType; + public String avatarAudio; + public String avatarAudioType; + public String avatarBackground; + public String speech; - public void parseXML(Element element) { - this.conversation = element.getAttribute("conversation"); - this.emote = element.getAttribute("emote"); - this.action = element.getAttribute("action"); - this.pose = element.getAttribute("pose"); - this.avatar = element.getAttribute("avatar"); - this.avatar2 = element.getAttribute("avatar2"); - this.avatar3 = element.getAttribute("avatar3"); - this.avatar4 = element.getAttribute("avatar4"); - this.avatar5 = element.getAttribute("avatar5"); - this.avatarType = element.getAttribute("avatarType"); - this.avatarTalk = element.getAttribute("avatarTalk"); - this.avatarTalkType = element.getAttribute("avatarTalkType"); - this.avatarAction = element.getAttribute("avatarAction"); - this.avatarActionType = element.getAttribute("avatarActionType"); - this.avatarActionAudio = element.getAttribute("avatarActionAudio"); - this.avatarActionAudioType = element.getAttribute("avatarActionAudioType"); - this.avatarAudio = element.getAttribute("avatarAudio"); - this.avatarAudioType = element.getAttribute("avatarAudioType"); - this.avatarBackground = element.getAttribute("avatarBackground"); - this.speech = element.getAttribute("speech"); - this.command = element.getAttribute("command"); + public boolean isVideo() { + return this.avatarType != null && this.avatarType.indexOf("video") != -1; + } - Node node = element.getElementsByTagName("message").item(0); - if (node != null) { - this.message = node.getTextContent(); - } - node = element.getElementsByTagName("question").item(0); - if (node != null) { - this.question = node.getTextContent(); - } - } - - public ZSONObject getCommand(){ - if (this.command == null || this.command.equals("")){ - return null; - } - try { - return new ZSONObject(); - } catch (ZSONException exception) { - exception.printStackTrace(); - } - return null; - } + public boolean isVideoTalk() { + return this.avatarTalkType != null && this.avatarTalkType.indexOf("video") != -1; + } + + public void parseXML(Element element) { + this.conversation = element.getAttribute("conversation"); + this.emote = element.getAttribute("emote"); + this.action = element.getAttribute("action"); + this.pose = element.getAttribute("pose"); + this.avatar = element.getAttribute("avatar"); + this.avatar2 = element.getAttribute("avatar2"); + this.avatar3 = element.getAttribute("avatar3"); + this.avatar4 = element.getAttribute("avatar4"); + this.avatar5 = element.getAttribute("avatar5"); + this.avatarType = element.getAttribute("avatarType"); + this.avatarTalk = element.getAttribute("avatarTalk"); + this.avatarTalkType = element.getAttribute("avatarTalkType"); + this.avatarAction = element.getAttribute("avatarAction"); + this.avatarActionType = element.getAttribute("avatarActionType"); + this.avatarActionAudio = element.getAttribute("avatarActionAudio"); + this.avatarActionAudioType = element.getAttribute("avatarActionAudioType"); + this.avatarAudio = element.getAttribute("avatarAudio"); + this.avatarAudioType = element.getAttribute("avatarAudioType"); + this.avatarBackground = element.getAttribute("avatarBackground"); + this.speech = element.getAttribute("speech"); + this.command = element.getAttribute("command"); + + Node node = element.getElementsByTagName("message").item(0); + if (node != null) { + this.message = node.getTextContent(); + } + node = element.getElementsByTagName("question").item(0); + if (node != null) { + this.question = node.getTextContent(); + } + } + + public ZSONObject getCommand() { + if (this.command == null || this.command.equals("")) { + return null; + } + try { + return new ZSONObject(); + } catch (ZSONException exception) { + exception.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/Config.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/Config.java index f2984ab..208cd84 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/Config.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/Config.java @@ -27,63 +27,63 @@ import org.w3c.dom.Element; * DTO for XML config. */ public class Config implements Cloneable { - public String application; - public String domain; - public String user; - public String token; - public String instance; - public String type; - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException exception) { - throw new Error(exception); - } - } - - public void addCredentials(SDKConnection connection) { - this.application = connection.getCredentials().getApplicationId(); - if (this.user == null && connection.getUser() != null) { - this.user = connection.getUser().user; - this.token = connection.getUser().token; - } - if (this.domain == null && connection.getDomain() != null) { - this.domain = connection.getDomain().id; - } - } - - public String toXML() { - return ""; - } - - public void parseXML(Element element) { - this.application = element.getAttribute("application"); - this.domain = element.getAttribute("domain"); - this.user = element.getAttribute("user"); - this.token = element.getAttribute("token"); - this.instance = element.getAttribute("instance"); - this.type = element.getAttribute("type"); - } - - public void writeCredentials(StringWriter writer) { - if (this.user != null && this.user.length() > 0) { - writer.write(" user=\"" + this.user + "\""); - } - if (this.token != null && this.token.length() > 0) { - writer.write(" token=\"" + this.token + "\""); - } - if (this.type != null && !this.type.equals("")) { - writer.write(" type=\"" + this.type + "\""); - } - if (this.instance != null && !this.instance.equals("")) { - writer.write(" instance=\"" + this.instance + "\""); - } - if (this.application != null && !this.application.equals("")) { - writer.write(" application=\"" + this.application + "\""); - } - if (this.domain != null && !this.domain.equals("")) { - writer.write(" domain=\"" + this.domain + "\""); - } - } + public String application; + public String domain; + public String user; + public String token; + public String instance; + public String type; + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException exception) { + throw new Error(exception); + } + } + + public void addCredentials(SDKConnection connection) { + this.application = connection.getCredentials().getApplicationId(); + if (this.user == null && connection.getUser() != null) { + this.user = connection.getUser().user; + this.token = connection.getUser().token; + } + if (this.domain == null && connection.getDomain() != null) { + this.domain = connection.getDomain().id; + } + } + + public String toXML() { + return ""; + } + + public void parseXML(Element element) { + this.application = element.getAttribute("application"); + this.domain = element.getAttribute("domain"); + this.user = element.getAttribute("user"); + this.token = element.getAttribute("token"); + this.instance = element.getAttribute("instance"); + this.type = element.getAttribute("type"); + } + + public void writeCredentials(StringWriter writer) { + if (this.user != null && this.user.length() > 0) { + writer.write(" user=\"" + this.user + "\""); + } + if (this.token != null && this.token.length() > 0) { + writer.write(" token=\"" + this.token + "\""); + } + if (this.type != null && !this.type.equals("")) { + writer.write(" type=\"" + this.type + "\""); + } + if (this.instance != null && !this.instance.equals("")) { + writer.write(" instance=\"" + this.instance + "\""); + } + if (this.application != null && !this.application.equals("")) { + writer.write(" application=\"" + this.application + "\""); + } + if (this.domain != null && !this.domain.equals("")) { + writer.write(" domain=\"" + this.domain + "\""); + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java deleted file mode 100644 index 205cead..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -/** - * DTO for XML content config. - */ -public class ContentConfig extends Config { - - public String types; - public String name; - public String icon; - public String description; - - public void parseXML(Element element) { - super.parseXML(element); - - this.types = element.getAttribute("type"); - this.name = element.getAttribute("name"); - this.icon = element.getAttribute("icon"); - - Node node = element.getElementsByTagName("description").item(0); - if (node != null) { - this.description = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java deleted file mode 100644 index b61bbca..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.botlibre.sdk.config; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import org.botlibre.sdk.util.Utils; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - - -/** - * DTO for XML conversation config. - */ -public class ConversationConfig extends Config { - public String id; - public String creationDate; - public String types; - - public List input; - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.types = element.getAttribute("type"); - - NodeList nodes = element.getElementsByTagName("input"); - if (nodes != null && nodes.getLength() > 0) { - this.input = new ArrayList(); - for (int index = 0; index < nodes.getLength(); index++) { - Element node = (Element)nodes.item(index); - InputConfig config = new InputConfig(); - config.parseXML(node); - this.input.add(config); - } - } - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java index 6eee6ee..46d4cb6 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java @@ -26,31 +26,31 @@ import org.w3c.dom.Element; * DTO for XML domain config. */ public class DomainConfig extends WebMediumConfig { - public String creationMode; - - public String getType() { - return "domain"; - } - - public WebMediumConfig credentials() { - DomainConfig config = new DomainConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.creationMode = element.getAttribute("creationMode"); - } + public String creationMode; + + public String getType() { + return "domain"; + } + + public WebMediumConfig credentials() { + DomainConfig config = new DomainConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.creationMode = element.getAttribute("creationMode"); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java index 679f144..aab18b4 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java @@ -26,43 +26,43 @@ import org.w3c.dom.Element; * DTO for XML forum config. */ public class ForumConfig extends WebMediumConfig { - public String replyAccessMode; - public String postAccessMode; - public String posts; - - public String getType() { - return "forum"; - } + public String replyAccessMode; + public String postAccessMode; + public String posts; - @Override - public String stats() { - return this.posts + " posts"; - } - - public WebMediumConfig credentials() { - ForumConfig config = new ForumConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.replyAccessMode = element.getAttribute("replyAccessMode"); - this.postAccessMode = element.getAttribute("postAccessMode"); - this.posts = element.getAttribute("posts"); - } + public String getType() { + return "forum"; + } + + @Override + public String stats() { + return this.posts + " posts"; + } + + public WebMediumConfig credentials() { + ForumConfig config = new ForumConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.replyAccessMode = element.getAttribute("replyAccessMode"); + this.postAccessMode = element.getAttribute("postAccessMode"); + this.posts = element.getAttribute("posts"); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java index e8133da..70ba726 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java @@ -35,172 +35,173 @@ import org.w3c.dom.NodeList; /** * DTO for XML forum post config. */ -public class ForumPostConfig extends Config { - public String id; - public String topic; - public String summary; - public String details; - public String detailsText; - public String forum; - public String tags; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public boolean isAdmin; - public boolean isFlagged; - public String flaggedReason; - public boolean isFeatured; - public String creator; - public String creationDate; - public String views; - public String dailyViews; - public String weeklyViews; - public String monthlyViews; - public String replyCount; - public String parent; - public String avatar; - public List replies; - - public boolean equals(Object object) { - if (object instanceof ForumPostConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((ForumPostConfig)object).id); - } - return false; - } +public class ForumPostConfig extends Config { + public String id; + public String topic; + public String summary; + public String details; + public String detailsText; + public String forum; + public String tags; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public boolean isAdmin; + public boolean isFlagged; + public String flaggedReason; + public boolean isFeatured; + public String creator; + public String creationDate; + public String views; + public String dailyViews; + public String weeklyViews; + public String monthlyViews; + public String replyCount; + public String parent; + public String avatar; + public List replies; - @Override - public int hashCode() { - return Objects.hash(id, topic, summary, details, detailsText, forum, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isFeatured, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, replyCount, parent, avatar, replies); - } + public boolean equals(Object object) { + if (object instanceof ForumPostConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((ForumPostConfig) object).id); + } + return false; + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + @Override + public int hashCode() { + return Objects.hash(id, topic, summary, details, detailsText, forum, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isFeatured, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, replyCount, parent, avatar, replies); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.topic != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.topic)); - writer.write(""); - } - if (this.details != null) { - String text = this.details; - writer.write("
"); - writer.write(Utils.escapeHTML(text)); - writer.write("
"); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.parent = element.getAttribute("parent"); - this.forum = element.getAttribute("forum"); - this.views = element.getAttribute("views"); - this.dailyViews = element.getAttribute("dailyViews"); - this.weeklyViews = element.getAttribute("weeklyViews"); - this.monthlyViews = element.getAttribute("monthlyViews"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.replyCount = element.getAttribute("replyCount"); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("summary").item(0); - if (node != null) { - this.summary = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("detailsText").item(0); - if (node != null) { - this.detailsText = node.getTextContent(); - } - node = element.getElementsByTagName("topic").item(0); - if (node != null) { - this.topic = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - NodeList nodes = element.getElementsByTagName("replies"); - if (nodes != null && nodes.getLength() > 0) { - this.replies = new ArrayList(); - for (int index = 0; index < nodes.getLength(); index++) { - Element reply = (Element)nodes.item(index); - ForumPostConfig config = new ForumPostConfig(); - config.parseXML(reply); - this.replies.add(config); - } - } - } - public ForumPostConfig credentials() { - ForumPostConfig config = new ForumPostConfig(); - config.id = this.id; - return config; - } + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.topic != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.topic)); + writer.write(""); + } + if (this.details != null) { + String text = this.details; + writer.write("
"); + writer.write(Utils.escapeHTML(text)); + writer.write("
"); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.parent = element.getAttribute("parent"); + this.forum = element.getAttribute("forum"); + this.views = element.getAttribute("views"); + this.dailyViews = element.getAttribute("dailyViews"); + this.weeklyViews = element.getAttribute("weeklyViews"); + this.monthlyViews = element.getAttribute("monthlyViews"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.replyCount = element.getAttribute("replyCount"); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("summary").item(0); + if (node != null) { + this.summary = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("detailsText").item(0); + if (node != null) { + this.detailsText = node.getTextContent(); + } + node = element.getElementsByTagName("topic").item(0); + if (node != null) { + this.topic = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + NodeList nodes = element.getElementsByTagName("replies"); + if (nodes != null && nodes.getLength() > 0) { + this.replies = new ArrayList(); + for (int index = 0; index < nodes.getLength(); index++) { + Element reply = (Element) nodes.item(index); + ForumPostConfig config = new ForumPostConfig(); + config.parseXML(reply); + this.replies.add(config); + } + } + } + + public ForumPostConfig credentials() { + ForumPostConfig config = new ForumPostConfig(); + config.id = this.id; + return config; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayTimestamp(date); + } catch (Exception exception) { + return creationDate; + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java index 6fedbf0..1d5d9b7 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java @@ -7,59 +7,61 @@ import org.w3c.dom.Element; /** * DTO for XML graphic config. */ -public class GraphicConfig extends WebMediumConfig{ - public String media; - public String fileName; - public String fileType; - - - @Override - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } +public class GraphicConfig extends WebMediumConfig { + public String media; + public String fileName; + public String fileType; - @Override - public String getType() { - return "graphic"; - } - @Override - public WebMediumConfig credentials() { - GraphicConfig config = new GraphicConfig(); - config.id = this.id; - return config; - } - public void parseXML(Element element) { - super.parseXML(element); - this.media = element.getAttribute("media"); - this.fileName = element.getAttribute("fileName"); - this.fileType = element.getAttribute("fileType"); + @Override + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + @Override + public String getType() { + return "graphic"; + } + + @Override + public WebMediumConfig credentials() { + GraphicConfig config = new GraphicConfig(); + config.id = this.id; + return config; + } + + public void parseXML(Element element) { + super.parseXML(element); + this.media = element.getAttribute("media"); + this.fileName = element.getAttribute("fileName"); + this.fileType = element.getAttribute("fileType"); // Node node = element.getElementsByTagName("media").item(0); // if (node != null) { // this.media = node.getTextContent(); // } - } - public boolean isVideo() { - return this.fileType != null && this.fileType.indexOf("video") != -1; - - } - - public boolean isAudio() { - return this.fileType != null && this.fileType.indexOf("audio") != -1; - } + } + + public boolean isVideo() { + return this.fileType != null && this.fileType.indexOf("video") != -1; + + } + + public boolean isAudio() { + return this.fileType != null && this.fileType.indexOf("audio") != -1; + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java deleted file mode 100644 index 9c99d0f..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import org.botlibre.util.Utils; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - - -/** - * DTO for XML input config. - */ -public class InputConfig extends Config { - public String id; - public String creationDate; - public String speaker; - public String target; - public String value; - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.speaker = element.getAttribute("speaker"); - this.target = element.getAttribute("target"); - - Node node = element.getElementsByTagName("value").item(0); - if (node != null) { - this.value = node.getTextContent(); - } - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTime(date); - } catch (Exception exception) { - return creationDate; - } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java index 59e8f80..7820784 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java @@ -27,69 +27,69 @@ import org.w3c.dom.Node; * DTO for XML bot instance config. */ public class InstanceConfig extends WebMediumConfig { - public String size; - public String instanceAvatar; - public boolean allowForking; - public boolean hasAPI; - public String template; - public int rank; - public int wins; - public int losses; - - public String getType() { - return "instance"; - } + public String size; + public String instanceAvatar; + public boolean allowForking; + public boolean hasAPI; + public String template; + public int rank; + public int wins; + public int losses; - @Override - public String stats() { - return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month"; - } + public String getType() { + return "instance"; + } - @Override - public InstanceConfig credentials() { - InstanceConfig config = new InstanceConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - writer.write(this.template); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.allowForking = Boolean.valueOf(element.getAttribute("allowForking")); - this.hasAPI = Boolean.valueOf(element.getAttribute("hasAPI")); - this.size = element.getAttribute("size"); - this.instanceAvatar = element.getAttribute("instanceAvatar"); - if (element.getAttribute("rank") != null && element.getAttribute("rank").trim().length() > 0) { - this.rank = Integer.valueOf(element.getAttribute("rank")); - } - if (element.getAttribute("wins") != null && element.getAttribute("wins").trim().length() > 0) { - this.wins = Integer.valueOf(element.getAttribute("wins")); - } - if (element.getAttribute("losses") != null && element.getAttribute("losses").trim().length() > 0) { - this.losses = Integer.valueOf(element.getAttribute("losses")); - } - - Node node = element.getElementsByTagName("template").item(0); - if (node != null) { - this.template = node.getTextContent(); - } - } + @Override + public String stats() { + return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month"; + } + + @Override + public InstanceConfig credentials() { + InstanceConfig config = new InstanceConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + writer.write(this.template); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.allowForking = Boolean.valueOf(element.getAttribute("allowForking")); + this.hasAPI = Boolean.valueOf(element.getAttribute("hasAPI")); + this.size = element.getAttribute("size"); + this.instanceAvatar = element.getAttribute("instanceAvatar"); + if (element.getAttribute("rank") != null && element.getAttribute("rank").trim().length() > 0) { + this.rank = Integer.valueOf(element.getAttribute("rank")); + } + if (element.getAttribute("wins") != null && element.getAttribute("wins").trim().length() > 0) { + this.wins = Integer.valueOf(element.getAttribute("wins")); + } + if (element.getAttribute("losses") != null && element.getAttribute("losses").trim().length() > 0) { + this.losses = Integer.valueOf(element.getAttribute("losses")); + } + + Node node = element.getElementsByTagName("template").item(0); + if (node != null) { + this.template = node.getTextContent(); + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java index 014f21d..33fd536 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java @@ -34,158 +34,159 @@ import java.util.Objects; * DTO for XML issue config. */ public class IssueConfig extends Config { - public String id; - public String title; - public String priority; - public String summary; - public String details; - public String detailsText; - public String tracker; - public String tags; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public boolean isAdmin; - public boolean isFlagged; - public String flaggedReason; - public boolean isPriority; - public String creator; - public String creationDate; - public String views; - public String dailyViews; - public String weeklyViews; - public String monthlyViews; - public String avatar; - - public boolean equals(Object object) { - if (object instanceof IssueConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((IssueConfig)object).id); - } - return false; - } + public String id; + public String title; + public String priority; + public String summary; + public String details; + public String detailsText; + public String tracker; + public String tags; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public boolean isAdmin; + public boolean isFlagged; + public String flaggedReason; + public boolean isPriority; + public String creator; + public String creationDate; + public String views; + public String dailyViews; + public String weeklyViews; + public String monthlyViews; + public String avatar; - @Override - public int hashCode() { - return Objects.hash(id, title, priority, summary, details, detailsText, tracker, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isPriority, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, avatar); - } + public boolean equals(Object object) { + if (object instanceof IssueConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((IssueConfig) object).id); + } + return false; + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + @Override + public int hashCode() { + return Objects.hash(id, title, priority, summary, details, detailsText, tracker, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isPriority, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, avatar); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.title != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.title)); - writer.write(""); - } - if (this.details != null) { - String text = this.details; - writer.write("
"); - writer.write(Utils.escapeHTML(text)); - writer.write("
"); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.tracker = element.getAttribute("tracker"); - this.priority = element.getAttribute("priority"); - this.views = element.getAttribute("views"); - this.dailyViews = element.getAttribute("dailyViews"); - this.weeklyViews = element.getAttribute("weeklyViews"); - this.monthlyViews = element.getAttribute("monthlyViews"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isPriority = Boolean.valueOf(element.getAttribute("isPriority")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("summary").item(0); - if (node != null) { - this.summary = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("detailsText").item(0); - if (node != null) { - this.detailsText = node.getTextContent(); - } - node = element.getElementsByTagName("title").item(0); - if (node != null) { - this.title = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - } - public IssueConfig credentials() { - IssueConfig config = new IssueConfig(); - config.id = this.id; - return config; - } + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.title != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.title)); + writer.write(""); + } + if (this.details != null) { + String text = this.details; + writer.write("
"); + writer.write(Utils.escapeHTML(text)); + writer.write("
"); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.tracker = element.getAttribute("tracker"); + this.priority = element.getAttribute("priority"); + this.views = element.getAttribute("views"); + this.dailyViews = element.getAttribute("dailyViews"); + this.weeklyViews = element.getAttribute("weeklyViews"); + this.monthlyViews = element.getAttribute("monthlyViews"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isPriority = Boolean.valueOf(element.getAttribute("isPriority")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("summary").item(0); + if (node != null) { + this.summary = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("detailsText").item(0); + if (node != null) { + this.detailsText = node.getTextContent(); + } + node = element.getElementsByTagName("title").item(0); + if (node != null) { + this.title = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + } + + public IssueConfig credentials() { + IssueConfig config = new IssueConfig(); + config.id = this.id; + return config; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayTimestamp(date); + } catch (Exception exception) { + return creationDate; + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java deleted file mode 100644 index 451d66c..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import org.w3c.dom.Element; - -import java.io.StringWriter; - -/** - * DTO for XML issue tracker config. - */ -public class IssueTrackerConfig extends WebMediumConfig { - public String createAccessMode; - public String issues; - - public String getType() { - return "issuetracker"; - } - - @Override - public String stats() { - return this.issues + " issues"; - } - - public WebMediumConfig credentials() { - IssueTrackerConfig config = new IssueTrackerConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.createAccessMode = element.getAttribute("createAccessMode"); - this.issues = element.getAttribute("issues"); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java index 772b30a..cc4c7b1 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java @@ -27,96 +27,98 @@ import org.w3c.dom.Element; * DTO for XML voice config. */ public class LearningConfig extends Config { - - public String learningMode; - public String learningRate; - public String correctionMode; - public boolean enableComprehension; - public boolean enableEmoting; - public boolean enableEmotions; - public boolean enableConsciousness; - public boolean enableWiktionary; - public boolean enableResponseMatch; - public boolean learnGrammar; - public boolean synthesizeResponse; - public boolean fixFormulaCase; - public boolean checkExactMatchFirst; - public int scriptTimeout; - public int responseMatchTimeout; - public String conversationMatchPercentage; - public String discussionMatchPercentage; - - public void parseXML(Element element) { - super.parseXML(element); - - this.learningMode = element.getAttribute("learningMode"); - this.learningRate = element.getAttribute("learningRate"); - this.correctionMode = element.getAttribute("correctionMode"); - this.enableComprehension = Boolean.valueOf(element.getAttribute("enableComprehension")); - this.enableEmoting = Boolean.valueOf(element.getAttribute("enableEmoting")); - this.enableEmotions = Boolean.valueOf(element.getAttribute("enableEmotions")); - this.enableConsciousness = Boolean.valueOf(element.getAttribute("enableConsciousness")); - this.enableWiktionary = Boolean.valueOf(element.getAttribute("enableWiktionary")); - this.enableResponseMatch = Boolean.valueOf(element.getAttribute("enableResponseMatch")); - this.learnGrammar = Boolean.valueOf(element.getAttribute("learnGrammar")); - this.synthesizeResponse = Boolean.valueOf(element.getAttribute("synthesizeResponse")); - this.fixFormulaCase = Boolean.valueOf(element.getAttribute("fixFormulaCase")); - this.checkExactMatchFirst = Boolean.valueOf(element.getAttribute("checkExactMatchFirst")); - String value = element.getAttribute("scriptTimeout"); - if (value != null && value.length() > 0) { - try { - this.scriptTimeout = Integer.valueOf(value); - } catch (Exception ignore) {} - } - value = element.getAttribute("responseMatchTimeout"); - if (value != null && value.length() > 0) { - try { - this.responseMatchTimeout = Integer.valueOf(value); - } catch (Exception ignore) {} - } - this.conversationMatchPercentage = element.getAttribute("conversationMatchPercentage"); - this.discussionMatchPercentage = element.getAttribute("discussionMatchPercentage"); - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(" 0) { - writer.write(" conversationMatchPercentage=\"" + this.conversationMatchPercentage + "\""); - } - if (this.discussionMatchPercentage != null && this.discussionMatchPercentage.length() > 0) { - writer.write(" discussionMatchPercentage=\"" + this.discussionMatchPercentage + "\""); - } - if (this.learningRate != null && this.learningRate.length() > 0) { - writer.write(" learningRate=\"" + this.learningRate + "\""); - } - - writer.write("/>"); - return writer.toString(); - } + public void parseXML(Element element) { + super.parseXML(element); + + this.learningMode = element.getAttribute("learningMode"); + this.learningRate = element.getAttribute("learningRate"); + this.correctionMode = element.getAttribute("correctionMode"); + this.enableComprehension = Boolean.valueOf(element.getAttribute("enableComprehension")); + this.enableEmoting = Boolean.valueOf(element.getAttribute("enableEmoting")); + this.enableEmotions = Boolean.valueOf(element.getAttribute("enableEmotions")); + this.enableConsciousness = Boolean.valueOf(element.getAttribute("enableConsciousness")); + this.enableWiktionary = Boolean.valueOf(element.getAttribute("enableWiktionary")); + this.enableResponseMatch = Boolean.valueOf(element.getAttribute("enableResponseMatch")); + this.learnGrammar = Boolean.valueOf(element.getAttribute("learnGrammar")); + this.synthesizeResponse = Boolean.valueOf(element.getAttribute("synthesizeResponse")); + this.fixFormulaCase = Boolean.valueOf(element.getAttribute("fixFormulaCase")); + this.checkExactMatchFirst = Boolean.valueOf(element.getAttribute("checkExactMatchFirst")); + String value = element.getAttribute("scriptTimeout"); + if (value != null && value.length() > 0) { + try { + this.scriptTimeout = Integer.valueOf(value); + } catch (Exception ignore) { + } + } + value = element.getAttribute("responseMatchTimeout"); + if (value != null && value.length() > 0) { + try { + this.responseMatchTimeout = Integer.valueOf(value); + } catch (Exception ignore) { + } + } + this.conversationMatchPercentage = element.getAttribute("conversationMatchPercentage"); + this.discussionMatchPercentage = element.getAttribute("discussionMatchPercentage"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(" 0) { + writer.write(" conversationMatchPercentage=\"" + this.conversationMatchPercentage + "\""); + } + if (this.discussionMatchPercentage != null && this.discussionMatchPercentage.length() > 0) { + writer.write(" discussionMatchPercentage=\"" + this.discussionMatchPercentage + "\""); + } + if (this.learningRate != null && this.learningRate.length() > 0) { + writer.write(" learningRate=\"" + this.learningRate + "\""); + } + + writer.write("/>"); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java deleted file mode 100644 index cb8e98b..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -import org.w3c.dom.Element; - - -/** - * DTO for XML media config. - */ -public class MediaConfig extends Config { - public long id; - public String name; - public String types; - public String file; - public String key; - - public void parseXML(Element element) { - super.parseXML(element); - - this.id = Long.valueOf(element.getAttribute("id")); - this.name = element.getAttribute("name"); - this.types = element.getAttribute("type"); - this.file = element.getAttribute("file"); - this.key = element.getAttribute("key"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java index 8984f85..0449961 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java @@ -15,87 +15,88 @@ * limitations under the License. * ******************************************************************************/ - + package org.botlibre.sdk.config; public class OfflineTemplateConfig { - private int imageId; - private int id_; - private String id; - private String title; - private String dec; - - public OfflineTemplateConfig(){ + private int imageId; + private int id_; + private String id; + private String title; + private String dec; + + public OfflineTemplateConfig() { + + } + + public OfflineTemplateConfig(int imageId, String title, String dec, String id) { + this.setImageId(imageId); + this.setTitle(title); + this.setDec(dec); + this.setId(id); + } + + public OfflineTemplateConfig(int imageId, String title, String dec, String id, int id_) { + this.setImageId(imageId); + this.setTitle(title); + this.setDec(dec); + this.setId(id); + this.setId_(id_); + } + + public int getImageId() { + return imageId; + } - } - - public OfflineTemplateConfig(int imageId, String title, String dec, String id){ - this.setImageId(imageId); - this.setTitle(title); - this.setDec(dec); - this.setId(id); - } - public OfflineTemplateConfig(int imageId, String title, String dec, String id,int id_){ - this.setImageId(imageId); - this.setTitle(title); - this.setDec(dec); - this.setId(id); - this.setId_(id_); - } - public int getImageId() { - return imageId; - } + public void setImageId(int imageId) { + this.imageId = imageId; + } - public void setImageId(int imageId) { - this.imageId = imageId; - } + public String getTitle() { + return title; + } - public String getTitle() { - return title; - } + public void setTitle(String title) { + this.title = title; + } + @Override + public String toString() { + return title + "\n" + dec; - public void setTitle(String title) { - this.title = title; - } - - @Override - public String toString(){ - return title + "\n" + dec; - - } + } - public String getDec() { - return dec; - } + public String getDec() { + return dec; + } - public void setDec(String dec) { - this.dec = dec; - } + public void setDec(String dec) { + this.dec = dec; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public int getId_() { - return id_; - } + public int getId_() { + return id_; + } - public void setId_(int id_) { - this.id_ = id_; - } + public void setId_(int id_) { + this.id_ = id_; + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java index bf74806..36022bc 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java @@ -31,175 +31,175 @@ import org.w3c.dom.Node; /** * DTO for XML response config. */ -public class ResponseConfig extends Config { - public String questionId; - public String responseId; - public String question; - public String response; - public String previous; - public String onRepeat; - public String label; - public String topic; - public String keywords; - public String required; - public String emotions; - public String actions; - public String poses; - public boolean noRepeat; - public boolean requirePrevious; - public boolean requireTopic; - public boolean flagged; - public String correctness; - public String command; +public class ResponseConfig extends Config { + public String questionId; + public String responseId; + public String question; + public String response; + public String previous; + public String onRepeat; + public String label; + public String topic; + public String keywords; + public String required; + public String emotions; + public String actions; + public String poses; + public boolean noRepeat; + public boolean requirePrevious; + public boolean requireTopic; + public boolean flagged; + public String correctness; + public String command; - public ResponseConfig() { - - } - - public boolean equals(Object object) { - if (this == object) { - return true; - } - if ((object instanceof ResponseConfig) && (this.responseId != null) && !this.responseId.isEmpty() - && this.responseId.equals(((ResponseConfig)object).responseId)) { - if (((this.questionId == null) || this.questionId.isEmpty()) - && (((ResponseConfig)object).questionId == null) || ((ResponseConfig)object).questionId.isEmpty()) { - return true; - } - if ((this.questionId != null) && !this.questionId.isEmpty() - && this.questionId.equals(((ResponseConfig)object).questionId)) { - return true; - } - } - return super.equals(object); - } + public ResponseConfig() { - @Override - public int hashCode() { - return Objects.hash(questionId, responseId, question, response, previous, onRepeat, label, topic, keywords, required, emotions, actions, poses, noRepeat, requirePrevious, requireTopic, flagged, correctness, command); - } + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + public boolean equals(Object object) { + if (this == object) { + return true; + } + if ((object instanceof ResponseConfig) && (this.responseId != null) && !this.responseId.isEmpty() + && this.responseId.equals(((ResponseConfig) object).responseId)) { + if (((this.questionId == null) || this.questionId.isEmpty()) + && (((ResponseConfig) object).questionId == null) || ((ResponseConfig) object).questionId.isEmpty()) { + return true; + } + if ((this.questionId != null) && !this.questionId.isEmpty() + && this.questionId.equals(((ResponseConfig) object).questionId)) { + return true; + } + } + return super.equals(object); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.question != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.question)); - writer.write(""); - } - if (this.response != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.response)); - writer.write(""); - } - if (this.previous != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.previous)); - writer.write(""); - } - if (this.onRepeat != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.onRepeat)); - writer.write(""); - } - if (this.command != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.command)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.questionId = element.getAttribute("questionId"); - this.responseId = element.getAttribute("responseId"); - this.label = element.getAttribute("label"); - this.topic = element.getAttribute("topic"); - this.keywords = element.getAttribute("keywords"); - this.required = element.getAttribute("required"); - this.emotions = element.getAttribute("emotions"); - this.actions = element.getAttribute("actions"); - this.poses = element.getAttribute("poses"); - this.type = element.getAttribute("type"); - this.correctness = element.getAttribute("correctness"); - if (element.getAttribute("noRepeat") != null) { - this.noRepeat = Boolean.valueOf(element.getAttribute("noRepeat")); - } - if (element.getAttribute("flagged") != null) { - this.flagged = Boolean.valueOf(element.getAttribute("flagged")); - } - if (element.getAttribute("requireTopic") != null) { - this.requireTopic = Boolean.valueOf(element.getAttribute("requireTopic")); - } - if (element.getAttribute("requirePrevious") != null) { - this.requirePrevious = Boolean.valueOf(element.getAttribute("requirePrevious")); - } - - Node node = element.getElementsByTagName("question").item(0); - if (node != null) { - this.question = node.getTextContent(); - } - node = element.getElementsByTagName("response").item(0); - if (node != null) { - this.response = node.getTextContent(); - } - node = element.getElementsByTagName("command").item(0); - if (node != null) { - this.command = node.getTextContent(); - this.command = this.command.replace(""", "\""); - } - } - - public ZSONObject getCommand(){ - if (this.command == null || this.command.equals("")){ - return null; - } - try { - return new ZSONObject(); - } catch (ZSONException e) { - e.printStackTrace(); - } - return null; - } + @Override + public int hashCode() { + return Objects.hash(questionId, responseId, question, response, previous, onRepeat, label, topic, keywords, required, emotions, actions, poses, noRepeat, requirePrevious, requireTopic, flagged, correctness, command); + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } + + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.question != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.question)); + writer.write(""); + } + if (this.response != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.response)); + writer.write(""); + } + if (this.previous != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.previous)); + writer.write(""); + } + if (this.onRepeat != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.onRepeat)); + writer.write(""); + } + if (this.command != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.command)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.questionId = element.getAttribute("questionId"); + this.responseId = element.getAttribute("responseId"); + this.label = element.getAttribute("label"); + this.topic = element.getAttribute("topic"); + this.keywords = element.getAttribute("keywords"); + this.required = element.getAttribute("required"); + this.emotions = element.getAttribute("emotions"); + this.actions = element.getAttribute("actions"); + this.poses = element.getAttribute("poses"); + this.type = element.getAttribute("type"); + this.correctness = element.getAttribute("correctness"); + if (element.getAttribute("noRepeat") != null) { + this.noRepeat = Boolean.valueOf(element.getAttribute("noRepeat")); + } + if (element.getAttribute("flagged") != null) { + this.flagged = Boolean.valueOf(element.getAttribute("flagged")); + } + if (element.getAttribute("requireTopic") != null) { + this.requireTopic = Boolean.valueOf(element.getAttribute("requireTopic")); + } + if (element.getAttribute("requirePrevious") != null) { + this.requirePrevious = Boolean.valueOf(element.getAttribute("requirePrevious")); + } + + Node node = element.getElementsByTagName("question").item(0); + if (node != null) { + this.question = node.getTextContent(); + } + node = element.getElementsByTagName("response").item(0); + if (node != null) { + this.response = node.getTextContent(); + } + node = element.getElementsByTagName("command").item(0); + if (node != null) { + this.command = node.getTextContent(); + this.command = this.command.replace(""", "\""); + } + } + + public ZSONObject getCommand() { + if (this.command == null || this.command.equals("")) { + return null; + } + try { + return new ZSONObject(); + } catch (ZSONException e) { + e.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java deleted file mode 100644 index c8bddf6..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -/** - * DTO for XML response search options. - */ -public class ResponseSearchConfig extends Config { - public String responseType; - public String inputType; - public String filter; - public String duration; - public String restrict; - public String page; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java index a536caf..d7b0c0c 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java @@ -21,45 +21,44 @@ import java.io.StringWriter; import org.w3c.dom.Element; public class ScriptConfig extends WebMediumConfig { - public String language; - public String version; + public String language; + public String version; - public String getType() { - return "script"; - } + public String getType() { + return "script"; + } - public WebMediumConfig credentials() { - ScriptConfig config = new ScriptConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - return writer.toString(); - } - - public void parseXML(Element element){ - super.parseXML(element); - this.language = element.getAttribute("language"); - this.version = element.getAttribute("version"); - } - - @Override - public String toString() { - return this.name; - } - + public WebMediumConfig credentials() { + ScriptConfig config = new ScriptConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.language = element.getAttribute("language"); + this.version = element.getAttribute("version"); + } + + @Override + public String toString() { + return this.name; + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java index b90dfe5..8ff3cdc 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java @@ -42,87 +42,86 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -public class ScriptSourceConfig extends Config{ - public String id; - public String creationDate; - public String updateDate; - public boolean version; - public String versionName; - public String creator; - public String source; - - public ScriptSourceConfig credentials() { - ScriptSourceConfig config = new ScriptSourceConfig(); - config.creator = this.creator; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.source != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.source)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element){ - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.updateDate = element.getAttribute("updateDate"); - this.version = Boolean.valueOf(element.getAttribute("version")); - this.versionName = element.getAttribute("versionName"); - this.creator = element.getAttribute("creator"); - - Node node = element.getElementsByTagName("source").item(0); - if (node != null) { - this.source = node.getTextContent(); - } - } - - public String getNextVersion() { - if (this.source == null) { - return "0.1"; - } - - String version = this.source; - int index = version.lastIndexOf('.'); - if (index != -1) { - String major = version.substring(0, index); - String minor = version.substring(index + 1, version.length()); - try { - int value = Integer.valueOf(minor); - version = major + "." + (value + 1); - } - catch (NumberFormatException ignore) { - } - } - return version; - } +public class ScriptSourceConfig extends Config { + public String id; + public String creationDate; + public String updateDate; + public boolean version; + public String versionName; + public String creator; + public String source; + + public ScriptSourceConfig credentials() { + ScriptSourceConfig config = new ScriptSourceConfig(); + config.creator = this.creator; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.source != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.source)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.creationDate = element.getAttribute("creationDate"); + this.updateDate = element.getAttribute("updateDate"); + this.version = Boolean.valueOf(element.getAttribute("version")); + this.versionName = element.getAttribute("versionName"); + this.creator = element.getAttribute("creator"); + + Node node = element.getElementsByTagName("source").item(0); + if (node != null) { + this.source = node.getTextContent(); + } + } + + public String getNextVersion() { + if (this.source == null) { + return "0.1"; + } + + String version = this.source; + int index = version.lastIndexOf('.'); + if (index != -1) { + String major = version.substring(0, index); + String minor = version.substring(index + 1, version.length()); + try { + int value = Integer.valueOf(minor); + version = major + "." + (value + 1); + } catch (NumberFormatException ignore) { + } + } + return version; + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/Speech.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/Speech.java deleted file mode 100644 index 63a6d47..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/Speech.java +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -/** - * A speech object can be used to invoke server-side text-to-speech. - * The object takes a message text, and a voice. - */ -public class Speech extends Config { - public String text; - public String voice; - public String mod; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java deleted file mode 100644 index 0bb5194..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import org.botlibre.util.Utils; - -import java.io.StringWriter; - - - -/** - * DTO for XML training config. - */ -public class TrainingConfig extends Config { - public String operation; - public String question; - public String response; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.question != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.question)); - writer.write(""); - } - if (this.response != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.response)); - writer.write(""); - } - - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java deleted file mode 100644 index b68c510..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -import org.w3c.dom.Element; - - -/** - * DTO for XML user admin config. - */ -public class UserAdminConfig extends Config { - public String operation; - public String operationUser; - - public void parseXML(Element element) { - super.parseXML(element); - - this.operation = element.getAttribute("operation"); - this.operationUser = element.getAttribute("operationUser"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java index d726118..50dcc8d 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java @@ -16,150 +16,150 @@ import org.botlibre.sdk.util.Utils; * DTO for XML user creation config. */ public class UserConfig extends Config { - public String password; - public String newPassword; - public String hint; - public String name; - public boolean showName; - public String email; - public String website; - public String bio; - public boolean over18; - public String avatar; - - public String connects; - public String bots; - public String posts; - public String messages; - public String forums; - public String scripts; - public String graphics; - public String avatars; - public String domains; - public String channels; - - public String joined; - public String lastConnect; - public String types; - public boolean isFlagged; - public String flaggedReason; - - public String displayJoined() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(joined); - return Utils.displayDate(date); - } catch (Exception exception) { - return joined; - } - } - - public String displayLastConnect() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(lastConnect); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return lastConnect; - } - } - - public void addCredentials(SDKConnection connection) { - this.application = connection.getCredentials().getApplicationId(); - if (connection.getDomain() != null) { - this.domain = connection.getDomain().id; - } - } - - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (!(object instanceof UserConfig)) { - return false; - } - return this.user != null && this.user.equals(((UserConfig)object).user); - } - - @Override - public int hashCode() { - return Objects.hash(password, newPassword, hint, name, showName, email, website, bio, over18, avatar, connects, bots, posts, messages, forums, scripts, graphics, avatars, domains, channels, joined, lastConnect, type, isFlagged, flaggedReason); - } - - public void parseXML(Element element) { - this.user = element.getAttribute("user"); - this.name = element.getAttribute("name"); - this.showName = Boolean.valueOf(element.getAttribute("showName")); - this.token = element.getAttribute("token"); - this.email = element.getAttribute("email"); - this.hint = element.getAttribute("hint"); - this.website = element.getAttribute("website"); - this.connects = element.getAttribute("connects"); - this.bots = element.getAttribute("bots"); - this.posts = element.getAttribute("posts"); - this.messages = element.getAttribute("messages"); - this.forums = element.getAttribute("forums"); - this.channels = element.getAttribute("channels"); - this.avatars = element.getAttribute("avatars"); - this.scripts = element.getAttribute("scripts"); - this.graphics = element.getAttribute("graphics"); - this.domains = element.getAttribute("domains"); - this.joined = element.getAttribute("joined"); - this.lastConnect = element.getAttribute("lastConnect"); - this.types = element.getAttribute("type"); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - - Node node = element.getElementsByTagName("bio").item(0); - if (node != null) { - this.bio = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.bio != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.bio)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - + public String password; + public String newPassword; + public String hint; + public String name; + public boolean showName; + public String email; + public String website; + public String bio; + public boolean over18; + public String avatar; + + public String connects; + public String bots; + public String posts; + public String messages; + public String forums; + public String scripts; + public String graphics; + public String avatars; + public String domains; + public String channels; + + public String joined; + public String lastConnect; + public String types; + public boolean isFlagged; + public String flaggedReason; + + public String displayJoined() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(joined); + return Utils.displayDate(date); + } catch (Exception exception) { + return joined; + } + } + + public String displayLastConnect() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(lastConnect); + return Utils.displayTimestamp(date); + } catch (Exception exception) { + return lastConnect; + } + } + + public void addCredentials(SDKConnection connection) { + this.application = connection.getCredentials().getApplicationId(); + if (connection.getDomain() != null) { + this.domain = connection.getDomain().id; + } + } + + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (!(object instanceof UserConfig)) { + return false; + } + return this.user != null && this.user.equals(((UserConfig) object).user); + } + + @Override + public int hashCode() { + return Objects.hash(password, newPassword, hint, name, showName, email, website, bio, over18, avatar, connects, bots, posts, messages, forums, scripts, graphics, avatars, domains, channels, joined, lastConnect, type, isFlagged, flaggedReason); + } + + public void parseXML(Element element) { + this.user = element.getAttribute("user"); + this.name = element.getAttribute("name"); + this.showName = Boolean.valueOf(element.getAttribute("showName")); + this.token = element.getAttribute("token"); + this.email = element.getAttribute("email"); + this.hint = element.getAttribute("hint"); + this.website = element.getAttribute("website"); + this.connects = element.getAttribute("connects"); + this.bots = element.getAttribute("bots"); + this.posts = element.getAttribute("posts"); + this.messages = element.getAttribute("messages"); + this.forums = element.getAttribute("forums"); + this.channels = element.getAttribute("channels"); + this.avatars = element.getAttribute("avatars"); + this.scripts = element.getAttribute("scripts"); + this.graphics = element.getAttribute("graphics"); + this.domains = element.getAttribute("domains"); + this.joined = element.getAttribute("joined"); + this.lastConnect = element.getAttribute("lastConnect"); + this.types = element.getAttribute("type"); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + + Node node = element.getElementsByTagName("bio").item(0); + if (node != null) { + this.bio = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.bio != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.bio)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java deleted file mode 100644 index 61e47a6..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java +++ /dev/null @@ -1,100 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.config; - -import java.io.StringWriter; - -import org.botlibre.util.Utils; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -/** - * DTO for XML content config. - */ -public class UserMessageConfig extends Config { - public String id; - public String creationDate; - public String owner; - public String creator; - public String target; - public String parent; - public String subject; - public String message; - - public void parseXML(Element element) { - super.parseXML(element); - - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.owner = element.getAttribute("owner"); - this.creator = element.getAttribute("creator"); - this.target = element.getAttribute("target"); - this.parent = element.getAttribute("parent"); - - Node node = element.getElementsByTagName("subject").item(0); - if (node != null) { - this.subject = node.getTextContent(); - } - node = element.getElementsByTagName("message").item(0); - if (node != null) { - this.message = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.subject != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.subject)); - writer.write(""); - } - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java index 2c9a81f..78b63ce 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java @@ -28,50 +28,50 @@ import org.w3c.dom.Element; */ public class VoiceConfig extends Config { - public String voice; - public boolean nativeVoice; - public String language; - public String pitch; - public String speechRate; - public String mod; - - public void parseXML(Element element) { - super.parseXML(element); + public String voice; + public boolean nativeVoice; + public String language; + public String pitch; + public String speechRate; + public String mod; - this.voice = element.getAttribute("voice"); - this.nativeVoice = Boolean.valueOf(element.getAttribute("nativeVoice")); - this.language = element.getAttribute("language"); - this.pitch = element.getAttribute("pitch"); - this.speechRate = element.getAttribute("speechRate"); - this.mod = element.getAttribute("mod"); - } + public void parseXML(Element element) { + super.parseXML(element); - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java index 5fe3920..1807c1c 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java @@ -33,240 +33,240 @@ import org.w3c.dom.Node; */ public abstract class WebMediumConfig extends Config { - public String id; - public String name; - public boolean isAdmin; - public boolean isAdult; - public boolean isPrivate; - public boolean isHidden; - public String accessMode; - public boolean isFlagged; - public boolean isExternal; - public boolean isPaphus; - public boolean showAds = true; - public String forkAccessMode; - public String contentRating; - public String description; - public String details; - public String disclaimer; - public String website; - public String subdomain; - public String tags; - public String categories; - public String flaggedReason; - public String creator; - public String creationDate; - public String lastConnectedUser; - public String license; - public String avatar; - public String script; - public String graphic; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public String connects; - public String dailyConnects; - public String weeklyConnects; - public String monthlyConnects; - - public abstract String toXML(); - - public abstract String getType(); - - public abstract WebMediumConfig credentials(); - - public String stats() { - return ""; - } - - public boolean equals(Object object) { - if (object instanceof WebMediumConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((WebMediumConfig)object).id); - } - return false; - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayDate(date); - } catch (Exception exception) { - return creationDate; - } - } - - public long getToken() { - long token = 0; - if ((this.token != null) && (this.token.equals(""))) { - token = Long.valueOf(this.token); - } - return token; - } + public String id; + public String name; + public boolean isAdmin; + public boolean isAdult; + public boolean isPrivate; + public boolean isHidden; + public String accessMode; + public boolean isFlagged; + public boolean isExternal; + public boolean isPaphus; + public boolean showAds = true; + public String forkAccessMode; + public String contentRating; + public String description; + public String details; + public String disclaimer; + public String website; + public String subdomain; + public String tags; + public String categories; + public String flaggedReason; + public String creator; + public String creationDate; + public String lastConnectedUser; + public String license; + public String avatar; + public String script; + public String graphic; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public String connects; + public String dailyConnects; + public String weeklyConnects; + public String monthlyConnects; - public void writeXML(StringWriter writer) { - writeCredentials(writer); - if (this.id != null) { - writer.write(" id=\"" + this.id + "\""); - } - if (this.name != null) { - writer.write(" name=\"" + this.name + "\""); - } - if (this.isPrivate) { - writer.write(" isPrivate=\"true\""); - } - if (this.isHidden) { - writer.write(" isHidden=\"true\""); - } - if (this.accessMode != null && !this.accessMode.equals("")) { - writer.write(" accessMode=\"" + this.accessMode + "\""); - } - if (this.contentRating != null && !this.contentRating.equals("")) { - writer.write(" contentRating=\"" + this.contentRating + "\""); - } - if (this.forkAccessMode != null && !this.forkAccessMode.equals("")) { - writer.write(" forkAccessMode=\"" + this.forkAccessMode + "\""); - } + public abstract String toXML(); - if (this.stars != null && !this.stars.equals("")) { - writer.write(" stars=\"" + this.stars + "\""); - } - if (this.isAdult) { - writer.write(" isAdult=\"true\""); - } - if (this.isFlagged) { - writer.write(" isFlagged=\"true\""); - } - if (this.isExternal) { - writer.write(" isExternal=\"true\""); - } - if (this.showAds) { - writer.write(" showAds=\"true\""); - } - writer.write(">"); - if (this.description != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.description)); - writer.write(""); - } - if (this.details != null) { - writer.write("
"); - writer.write(Utils.escapeHTML(this.details)); - writer.write("
"); - } - if (this.disclaimer != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.disclaimer)); - writer.write(""); - } - if (this.categories != null) { - writer.write(""); - writer.write(this.categories); - writer.write(""); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.license != null) { - writer.write(""); - writer.write(this.license); - writer.write(""); - } - if (this.website != null) { - writer.write(""); - writer.write(this.website); - writer.write(""); - } - if (this.subdomain != null) { - writer.write(""); - writer.write(this.subdomain); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.name = element.getAttribute("name"); - this.creationDate = element.getAttribute("creationDate"); - this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate")); - this.isHidden = Boolean.valueOf(element.getAttribute("isHidden")); - this.accessMode = element.getAttribute("accessMode"); - this.contentRating = element.getAttribute("contentRating"); - this.forkAccessMode = element.getAttribute("forkAccessMode"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.isAdult = Boolean.valueOf(element.getAttribute("isAdult")); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isExternal = Boolean.valueOf(element.getAttribute("isExternal")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - this.connects = element.getAttribute("connects"); - this.dailyConnects = element.getAttribute("dailyConnects"); - this.weeklyConnects = element.getAttribute("weeklyConnects"); - this.showAds = Boolean.valueOf(element.getAttribute("showAds")); - this.monthlyConnects = element.getAttribute("monthlyConnects"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("description").item(0); - if (node != null) { - this.description = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("disclaimer").item(0); - if (node != null) { - this.disclaimer = node.getTextContent(); - } - node = element.getElementsByTagName("categories").item(0); - if (node != null) { - this.categories = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("lastConnectedUser").item(0); - if (node != null) { - this.lastConnectedUser = node.getTextContent(); - } - node = element.getElementsByTagName("license").item(0); - if (node != null) { - this.license = node.getTextContent(); - } - node = element.getElementsByTagName("website").item(0); - if (node != null) { - this.website = node.getTextContent(); - } - node = element.getElementsByTagName("subdomain").item(0); - if (node != null) { - this.subdomain = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - } + public abstract String getType(); + + public abstract WebMediumConfig credentials(); + + public String stats() { + return ""; + } + + public boolean equals(Object object) { + if (object instanceof WebMediumConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((WebMediumConfig) object).id); + } + return false; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayDate(date); + } catch (Exception exception) { + return creationDate; + } + } + + public long getToken() { + long token = 0; + if ((this.token != null) && (this.token.equals(""))) { + token = Long.valueOf(this.token); + } + return token; + } + + public void writeXML(StringWriter writer) { + writeCredentials(writer); + if (this.id != null) { + writer.write(" id=\"" + this.id + "\""); + } + if (this.name != null) { + writer.write(" name=\"" + this.name + "\""); + } + if (this.isPrivate) { + writer.write(" isPrivate=\"true\""); + } + if (this.isHidden) { + writer.write(" isHidden=\"true\""); + } + if (this.accessMode != null && !this.accessMode.equals("")) { + writer.write(" accessMode=\"" + this.accessMode + "\""); + } + if (this.contentRating != null && !this.contentRating.equals("")) { + writer.write(" contentRating=\"" + this.contentRating + "\""); + } + if (this.forkAccessMode != null && !this.forkAccessMode.equals("")) { + writer.write(" forkAccessMode=\"" + this.forkAccessMode + "\""); + } + + if (this.stars != null && !this.stars.equals("")) { + writer.write(" stars=\"" + this.stars + "\""); + } + if (this.isAdult) { + writer.write(" isAdult=\"true\""); + } + if (this.isFlagged) { + writer.write(" isFlagged=\"true\""); + } + if (this.isExternal) { + writer.write(" isExternal=\"true\""); + } + if (this.showAds) { + writer.write(" showAds=\"true\""); + } + writer.write(">"); + if (this.description != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.description)); + writer.write(""); + } + if (this.details != null) { + writer.write("
"); + writer.write(Utils.escapeHTML(this.details)); + writer.write("
"); + } + if (this.disclaimer != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.disclaimer)); + writer.write(""); + } + if (this.categories != null) { + writer.write(""); + writer.write(this.categories); + writer.write(""); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.license != null) { + writer.write(""); + writer.write(this.license); + writer.write(""); + } + if (this.website != null) { + writer.write(""); + writer.write(this.website); + writer.write(""); + } + if (this.subdomain != null) { + writer.write(""); + writer.write(this.subdomain); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.name = element.getAttribute("name"); + this.creationDate = element.getAttribute("creationDate"); + this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate")); + this.isHidden = Boolean.valueOf(element.getAttribute("isHidden")); + this.accessMode = element.getAttribute("accessMode"); + this.contentRating = element.getAttribute("contentRating"); + this.forkAccessMode = element.getAttribute("forkAccessMode"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.isAdult = Boolean.valueOf(element.getAttribute("isAdult")); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isExternal = Boolean.valueOf(element.getAttribute("isExternal")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + this.connects = element.getAttribute("connects"); + this.dailyConnects = element.getAttribute("dailyConnects"); + this.weeklyConnects = element.getAttribute("weeklyConnects"); + this.showAds = Boolean.valueOf(element.getAttribute("showAds")); + this.monthlyConnects = element.getAttribute("monthlyConnects"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("description").item(0); + if (node != null) { + this.description = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("disclaimer").item(0); + if (node != null) { + this.disclaimer = node.getTextContent(); + } + node = element.getElementsByTagName("categories").item(0); + if (node != null) { + this.categories = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("lastConnectedUser").item(0); + if (node != null) { + this.lastConnectedUser = node.getTextContent(); + } + node = element.getElementsByTagName("license").item(0); + if (node != null) { + this.license = node.getTextContent(); + } + node = element.getElementsByTagName("website").item(0); + if (node != null) { + this.website = node.getTextContent(); + } + node = element.getElementsByTagName("subdomain").item(0); + if (node != null) { + this.subdomain = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + } } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/TextStream.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/TextStream.java index 7cce43a..990b3bf 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/TextStream.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/TextStream.java @@ -29,630 +29,630 @@ import java.util.Set; */ public class TextStream { - public static final String WHITESPACE =" \t\n\r\f"; - public static final String HTTP =" \t\n\r\f\""; - public static final String TOKENS =" \t\n\r\f.,:;!()?[]{}+=^&*\"`~|/\\<>"; - public static final String TERMINATORS =".?!。"; - public static final Set ABBREVIATIONS = new HashSet(Arrays.asList(new String[]{"mr","ms", "mrs", "dr", "inc", "sr", "jr", "st"})); - public static Set IGNORABLE = new HashSet(Arrays.asList(new String[]{"'","`", "\"", ","})); - - /** - * The text being streamed. - */ - protected String text; - - /** - * The current stream index into the text. - */ - protected int index; - - public TextStream(String text) { - this.index = 0; - this.text = text; - } - - public void reset() { - this.index = 0; - } - - public char last() { - if (this.index <= 1) { - return (char)0; - } - return this.text.charAt(this.index - 2); - } - - public char current() { - if (this.index <= 0) { - return (char)0; - } - return this.text.charAt(this.index - 1); - } - - public char peekPrevious() { - if (this.index <= 1) { - return (char)0; - } - return this.text.charAt(this.index - 2); - } - - public char peek() { - if (atEnd()) { - return (char)-1; - } - return this.text.charAt(this.index); - } - - public int peekCodePoint() { - if (atEnd()) { - return (int)-1; - } - return this.text.codePointAt(this.index); - } - - public char next() { - if (this.index >= this.text.length()) { - return (char)-1; - } - char next = this.text.charAt(this.index); - this.index++; - return next; - } - - public char previous() { - this.index--; - char previous = current(); - return previous; - } - - public void skip() { - if (this.index >= this.text.length()) { - return; - } - this.index++; - } - - public void skip(int count) { - this.index = Math.min(this.index + count, this.text.length()); - } - - public void backup(int count) { - this.index = Math.max(this.index - count, 0); - } - - public void backup() { - this.index--; - } - - public String peek(int count) { - int start = this.index; - int end = Math.min(this.index + count, this.text.length()); - return this.text.substring(start, end); - } - - public String previous(int count) { - int end = this.index - 2; - if (end <= 0) { - return ""; - } - int start = Math.max(end - count, 0); - return this.text.substring(start, end); - } - - public String next(int count) { - int start = this.index; - this.index = Math.min(this.index + count, this.text.length()); - return this.text.substring(start, this.index); - } - - public boolean atEnd() { - return this.index >= this.text.length(); - } - - public boolean atStart() { - return this.index == 0; - } - - public String upTo(char token) { - return upTo(token, false); - } - - public void skipTo(char token) { - skipTo(token, false); - } - - public String upToEnd() { - int start = this.index; - this.index = this.text.length(); - return this.text.substring(start, this.index); - } - - public String upTo(char token, boolean including) { - return upTo(token, including, false); - } - - public String upTo(char token, boolean including, boolean resetIfNotFound) { - int start = this.index; - boolean found = skipTo(token, including); - if (resetIfNotFound && !found) { - this.index = start; - return ""; - } - return this.text.substring(start, this.index); - } - - public boolean skipTo(char token, boolean including) { - boolean found = false; - while (!atEnd()) { - if (peek() == token) { - found = true; - break; - } - skip(); - } - if (found && including) { - skip(); - } - return found; - } - - public void backupTo(char token) { - backupTo(token, false); - } - - public void backupTo(char token, boolean including) { - boolean found = false; - while (this.index > 0) { - if (current() == token) { - found = true; - break; - } - backup(); - } - if (found && including) { - backup(); - } - } - - public String upToAny(String tokens) { - return upToAny(tokens, false); - } - - public String upToAny(String tokens, boolean including) { - int start = this.index; - skipToAny(tokens, including); - return this.text.substring(start, this.index); - } - - public void skipToAny(String tokens) { - skipToAny(tokens, false); - } - - public void skipToAny(String tokens, boolean including) { - boolean found = false; - while (!atEnd()) { - if (tokens.indexOf(peek()) != -1) { - found = true; - break; - } - skip(); - } - if (found && including) { - skip(); - } - } - - public String upToAll(String tokens) { - return upToAll(tokens, false); - } - - public String upToAll(String tokens, boolean including) { - return upToAll(tokens, including, false); - } - - public String upToAll(String tokens, boolean including, boolean resetIfNotFound) { - int start = this.index; - boolean found = skipToAll(tokens, including); - if (resetIfNotFound && !found) { - this.index = start; - return ""; - } - return this.text.substring(start, this.index); - } - - public void skipToAll(String tokens) { - skipToAll(tokens, false); - } - - public boolean skipToAll(String tokens, boolean including) { - int tokenIndex = 0; - boolean found = false; - while (!atEnd()) { - if (peek() == tokens.charAt(tokenIndex)) { - tokenIndex++; - if (tokenIndex == tokens.length()) { - found = true; - break; - } - } else { - tokenIndex = 0; - } - skip(); - } - if (found) { - if (including) { - skip(); - } else { - this.index = index - (tokens.length() - 1); - } - } - return found; - } - - public void backupToAll(String tokens) { - backupToAll(tokens, false); - } - - public void backupToAll(String tokens, boolean including) { - int tokenIndex = 1; - int length = tokens.length(); - boolean found = false; - while (this.index > 0) { - if (current() == tokens.charAt(length - tokenIndex)) { - if (tokenIndex == tokens.length()) { - found = true; - break; - } - tokenIndex++; - } else { - tokenIndex = 1; - } - backup(); - } - if (found) { - if (including) { - backup(); - } else { - this.index = index + (length - 1); - } - } - } - - public void backupToAny(String tokens) { - backupToAny(tokens, false); - } - - public void backupToAny(String tokens, boolean including) { - boolean found = false; - while (!atStart()) { - if (tokens.indexOf(peekPrevious()) != -1) { - found = true; - break; - } - backup(); - } - if (found && including) { - backup(); - } - } - - public String peekWord() { - int position = this.index; - String word = nextWord(); - this.index = position; - return word; - } - - public List allWords() { - List words = new ArrayList(); - while (!atEnd()) { - String word = nextWord(); - if (word != null) { - words.add(word); - } - } - return words; - } - - public List csv() { - List words = new ArrayList(); - skipWhitespace(); - while (!atEnd()) { - String word = upTo(','); - if (!atEnd()) { - skip(); - skipWhitespace(); - } - if ((word != null) && !word.trim().equals("")) { - words.add(word); - } - } - return words; - } - - public String peekPreviousWord() { - int original = this.index; - backupWhitespace(); - int start = this.index; - if (atStart()) { - return null; - } - char current = current(); - if ((TOKENS.indexOf(current) != -1) || (isWordSymbol(current))) { - previous(); - String word = String.valueOf(current); - this.index = original; - return word; - } - backupToAny(TOKENS); - String word = this.text.substring(Math.max(this.index - 1, 0), start); - this.index = original; - return word; - } - - public boolean isWordSymbol(char character) { - Character.UnicodeBlock block = Character.UnicodeBlock.of(character); - return ((block == Character.UnicodeBlock.HIRAGANA) - || (block == Character.UnicodeBlock.KATAKANA) - || (block == Character.UnicodeBlock.HANGUL_SYLLABLES) - || (block == Character.UnicodeBlock.HANGUL_JAMO)) - && !Character.isDigit(character); - } - - public String nextQuotes() { - if (atEnd()) { - return ""; - } - int start = this.index; - skipQuotes(); - int end = this.index - 1; - if (atEnd() && current() != '"') { - end = this.index; - } - String quotes = this.text.substring(start, end); - return quotes; - } - - public String nextQuotesExcludeDoubleQuote() { - String quotes = nextQuotes(); - if (quotes.contains("\"\"")) { - quotes = quotes.replace("\"\"", "\""); - } - return quotes; - } - - public void skipQuotes() { - if (atEnd()) { - return; - } - char next = next(); - char peek = peek(); - while (!atEnd() && ((next != '"') || (peek == '"'))) { - if ((next == '"') && (peek == '"')) { - skip(); - } - if (next == '{') { - skipBrackets(); - } - next = next(); - peek = peek(); - } - } - - public void skipBrackets() { - if (atEnd()) { - return; - } - char next = next(); - while (!atEnd() && (next != '}')) { - if (next == '"') { - skipQuotes(); - } - next = next(); - } - } - - public String nextWord() { - skipWhitespace(); - if (atEnd()) { - return null; - } - //int peek = peekCodePoint(); - char peek = peek(); - boolean isSign = (peek == '-') || (peek == '+'); - // Check for "1-1" vs "1 - -1" - if (isSign && !atStart()) { - backup(); - char previous = peek(); - if (Character.isLetterOrDigit(previous)) { - skip(); - skip(); - return String.valueOf(peek); - } - skip(); - } - if (isWordSymbol(peek) || (!Character.isLetterOrDigit(peek) && peek != '_' && peek != '@' && !isSign)) { - skip(); - Character.UnicodeBlock block = Character.UnicodeBlock.of(peek); - if (block == Character.UnicodeBlock.HIGH_SURROGATES) { - skip(); - return this.text.substring(this.index - 2, this.index); - } - return String.valueOf(peek); - } - // Check url. - if (peek == 'h') { - if (peek(7).equals("http://") || peek(8).equals("https://")) { - return upToAny(HTTP); - } - } - int start = this.index; - boolean wasDigit = Character.isDigit(peek); - skip(); - while (!atEnd()) { - //peek = peekCodePoint(); - peek = peek(); - boolean isDigit = Character.isDigit(peek); - if (isWordSymbol(peek)) { - break; - } - // "-1" is ok - if (isSign && !isDigit) { - break; - } else { - // Allow "1.1", "1,000", "ab-ba", "ab_ba" - if (!Character.isLetter(peek) && !isDigit && (peek != '_')) { - if (wasDigit) { - if ((peek != '.') && (peek != ',') && (peek != '@')) { - break; - } - } else { - if ((peek != '-') && (peek != '_') && (peek != '@') && (peek != '.')) { - break; - } - } - } - } - wasDigit = isDigit; - skip(); - // Could have been "1.", "1.a" - if ((((peek == '.') && !Character.isLetter(peek())) || (peek == ',')) && !Character.isDigit(peek())) { - backup(); - break; - } - isSign = false; - } - return this.text.substring(start, this.index); - } - - public void skipWord() { - skipWhitespace(); - if (atEnd()) { - return; - } - if (TOKENS.indexOf(peek()) != -1) { - skip(); - } - // Check url. - if (peek() == 'h') { - if (peek(7).equals("http://")) { - skipToAny(WHITESPACE); - } - } - skipToAny(TOKENS); - } - - public String nextSentence() { - skipWhitespace(); - if (atEnd()) { - return null; - } - int start = this.index; - skipToAny(TERMINATORS, true); - while (!atEnd()) { - char peek = peek(); - boolean done = WHITESPACE.indexOf(peek) != -1; - if (done) { - if (current() != '.') { - break; - } - backup(); - String word = peekPreviousWord(); - skip(); - if (ABBREVIATIONS.contains(word.toLowerCase()) - || ((word.length() == 1) && (Character.isUpperCase(word.charAt(0))))) { - done = false; - } else { - break; - } - } else if (isWordSymbol(peek)) { - break; - } - skipToAny(TERMINATORS, true); - } - return this.text.substring(start, this.index); - } - - public String nextWhitespace() { - int start = this.index; - while (!atEnd() && (WHITESPACE.indexOf(peek()) != -1)) { - skip(); - } - return this.text.substring(start, this.index); - } - - public boolean skipWhitespace() { - boolean found = false; - while (!atEnd() && (Character.isWhitespace(peek()))) { - skip(); - found = true; - } - return found; - } - - public void backupWhitespace() { - while (!atStart() && (WHITESPACE.indexOf(current()) != -1)) { - backup(); - } - } - - public String nextLine() { - return upToAll("\n", true); - } - - public String currentLine() { - int position = this.index; - backupToAll("\n"); - String line = nextLine(); - this.index = position; - return line; - } - - public int currentLineNumber() { - int position = this.index; - this.index = 0; - int count = 0; - int last = this.index; - while (this.index < position) { - skipLine(); - if (this.index < position) { - count++; - } - if (this.index == last) { - break; - } - last = this.index; - } - this.index = position; - return count + 1; - } - - public int currentLineColumn() { - int position = this.index; - backupToAll("\n"); - int column = position - this.index; - this.index = position; - return column + 1; - } - - public void skipLine() { - skipToAll("\n", true); - } - - public int getPosition() { - return index; - } - - public void setPosition(int index) { - this.index = index; - } - - public String getText() { - return text; - } - - public String toString() { - return peek(text.length()); - } - + public static final String WHITESPACE = " \t\n\r\f"; + public static final String HTTP = " \t\n\r\f\""; + public static final String TOKENS = " \t\n\r\f.,:;!()?[]{}+=^&*\"`~|/\\<>"; + public static final String TERMINATORS = ".?!。"; + public static final Set ABBREVIATIONS = new HashSet(Arrays.asList(new String[]{"mr", "ms", "mrs", "dr", "inc", "sr", "jr", "st"})); + public static Set IGNORABLE = new HashSet(Arrays.asList(new String[]{"'", "`", "\"", ","})); + + /** + * The text being streamed. + */ + protected String text; + + /** + * The current stream index into the text. + */ + protected int index; + + public TextStream(String text) { + this.index = 0; + this.text = text; + } + + public void reset() { + this.index = 0; + } + + public char last() { + if (this.index <= 1) { + return (char) 0; + } + return this.text.charAt(this.index - 2); + } + + public char current() { + if (this.index <= 0) { + return (char) 0; + } + return this.text.charAt(this.index - 1); + } + + public char peekPrevious() { + if (this.index <= 1) { + return (char) 0; + } + return this.text.charAt(this.index - 2); + } + + public char peek() { + if (atEnd()) { + return (char) -1; + } + return this.text.charAt(this.index); + } + + public int peekCodePoint() { + if (atEnd()) { + return (int) -1; + } + return this.text.codePointAt(this.index); + } + + public char next() { + if (this.index >= this.text.length()) { + return (char) -1; + } + char next = this.text.charAt(this.index); + this.index++; + return next; + } + + public char previous() { + this.index--; + char previous = current(); + return previous; + } + + public void skip() { + if (this.index >= this.text.length()) { + return; + } + this.index++; + } + + public void skip(int count) { + this.index = Math.min(this.index + count, this.text.length()); + } + + public void backup(int count) { + this.index = Math.max(this.index - count, 0); + } + + public void backup() { + this.index--; + } + + public String peek(int count) { + int start = this.index; + int end = Math.min(this.index + count, this.text.length()); + return this.text.substring(start, end); + } + + public String previous(int count) { + int end = this.index - 2; + if (end <= 0) { + return ""; + } + int start = Math.max(end - count, 0); + return this.text.substring(start, end); + } + + public String next(int count) { + int start = this.index; + this.index = Math.min(this.index + count, this.text.length()); + return this.text.substring(start, this.index); + } + + public boolean atEnd() { + return this.index >= this.text.length(); + } + + public boolean atStart() { + return this.index == 0; + } + + public String upTo(char token) { + return upTo(token, false); + } + + public void skipTo(char token) { + skipTo(token, false); + } + + public String upToEnd() { + int start = this.index; + this.index = this.text.length(); + return this.text.substring(start, this.index); + } + + public String upTo(char token, boolean including) { + return upTo(token, including, false); + } + + public String upTo(char token, boolean including, boolean resetIfNotFound) { + int start = this.index; + boolean found = skipTo(token, including); + if (resetIfNotFound && !found) { + this.index = start; + return ""; + } + return this.text.substring(start, this.index); + } + + public boolean skipTo(char token, boolean including) { + boolean found = false; + while (!atEnd()) { + if (peek() == token) { + found = true; + break; + } + skip(); + } + if (found && including) { + skip(); + } + return found; + } + + public void backupTo(char token) { + backupTo(token, false); + } + + public void backupTo(char token, boolean including) { + boolean found = false; + while (this.index > 0) { + if (current() == token) { + found = true; + break; + } + backup(); + } + if (found && including) { + backup(); + } + } + + public String upToAny(String tokens) { + return upToAny(tokens, false); + } + + public String upToAny(String tokens, boolean including) { + int start = this.index; + skipToAny(tokens, including); + return this.text.substring(start, this.index); + } + + public void skipToAny(String tokens) { + skipToAny(tokens, false); + } + + public void skipToAny(String tokens, boolean including) { + boolean found = false; + while (!atEnd()) { + if (tokens.indexOf(peek()) != -1) { + found = true; + break; + } + skip(); + } + if (found && including) { + skip(); + } + } + + public String upToAll(String tokens) { + return upToAll(tokens, false); + } + + public String upToAll(String tokens, boolean including) { + return upToAll(tokens, including, false); + } + + public String upToAll(String tokens, boolean including, boolean resetIfNotFound) { + int start = this.index; + boolean found = skipToAll(tokens, including); + if (resetIfNotFound && !found) { + this.index = start; + return ""; + } + return this.text.substring(start, this.index); + } + + public void skipToAll(String tokens) { + skipToAll(tokens, false); + } + + public boolean skipToAll(String tokens, boolean including) { + int tokenIndex = 0; + boolean found = false; + while (!atEnd()) { + if (peek() == tokens.charAt(tokenIndex)) { + tokenIndex++; + if (tokenIndex == tokens.length()) { + found = true; + break; + } + } else { + tokenIndex = 0; + } + skip(); + } + if (found) { + if (including) { + skip(); + } else { + this.index = index - (tokens.length() - 1); + } + } + return found; + } + + public void backupToAll(String tokens) { + backupToAll(tokens, false); + } + + public void backupToAll(String tokens, boolean including) { + int tokenIndex = 1; + int length = tokens.length(); + boolean found = false; + while (this.index > 0) { + if (current() == tokens.charAt(length - tokenIndex)) { + if (tokenIndex == tokens.length()) { + found = true; + break; + } + tokenIndex++; + } else { + tokenIndex = 1; + } + backup(); + } + if (found) { + if (including) { + backup(); + } else { + this.index = index + (length - 1); + } + } + } + + public void backupToAny(String tokens) { + backupToAny(tokens, false); + } + + public void backupToAny(String tokens, boolean including) { + boolean found = false; + while (!atStart()) { + if (tokens.indexOf(peekPrevious()) != -1) { + found = true; + break; + } + backup(); + } + if (found && including) { + backup(); + } + } + + public String peekWord() { + int position = this.index; + String word = nextWord(); + this.index = position; + return word; + } + + public List allWords() { + List words = new ArrayList(); + while (!atEnd()) { + String word = nextWord(); + if (word != null) { + words.add(word); + } + } + return words; + } + + public List csv() { + List words = new ArrayList(); + skipWhitespace(); + while (!atEnd()) { + String word = upTo(','); + if (!atEnd()) { + skip(); + skipWhitespace(); + } + if ((word != null) && !word.trim().equals("")) { + words.add(word); + } + } + return words; + } + + public String peekPreviousWord() { + int original = this.index; + backupWhitespace(); + int start = this.index; + if (atStart()) { + return null; + } + char current = current(); + if ((TOKENS.indexOf(current) != -1) || (isWordSymbol(current))) { + previous(); + String word = String.valueOf(current); + this.index = original; + return word; + } + backupToAny(TOKENS); + String word = this.text.substring(Math.max(this.index - 1, 0), start); + this.index = original; + return word; + } + + public boolean isWordSymbol(char character) { + Character.UnicodeBlock block = Character.UnicodeBlock.of(character); + return ((block == Character.UnicodeBlock.HIRAGANA) + || (block == Character.UnicodeBlock.KATAKANA) + || (block == Character.UnicodeBlock.HANGUL_SYLLABLES) + || (block == Character.UnicodeBlock.HANGUL_JAMO)) + && !Character.isDigit(character); + } + + public String nextQuotes() { + if (atEnd()) { + return ""; + } + int start = this.index; + skipQuotes(); + int end = this.index - 1; + if (atEnd() && current() != '"') { + end = this.index; + } + String quotes = this.text.substring(start, end); + return quotes; + } + + public String nextQuotesExcludeDoubleQuote() { + String quotes = nextQuotes(); + if (quotes.contains("\"\"")) { + quotes = quotes.replace("\"\"", "\""); + } + return quotes; + } + + public void skipQuotes() { + if (atEnd()) { + return; + } + char next = next(); + char peek = peek(); + while (!atEnd() && ((next != '"') || (peek == '"'))) { + if ((next == '"') && (peek == '"')) { + skip(); + } + if (next == '{') { + skipBrackets(); + } + next = next(); + peek = peek(); + } + } + + public void skipBrackets() { + if (atEnd()) { + return; + } + char next = next(); + while (!atEnd() && (next != '}')) { + if (next == '"') { + skipQuotes(); + } + next = next(); + } + } + + public String nextWord() { + skipWhitespace(); + if (atEnd()) { + return null; + } + //int peek = peekCodePoint(); + char peek = peek(); + boolean isSign = (peek == '-') || (peek == '+'); + // Check for "1-1" vs "1 - -1" + if (isSign && !atStart()) { + backup(); + char previous = peek(); + if (Character.isLetterOrDigit(previous)) { + skip(); + skip(); + return String.valueOf(peek); + } + skip(); + } + if (isWordSymbol(peek) || (!Character.isLetterOrDigit(peek) && peek != '_' && peek != '@' && !isSign)) { + skip(); + Character.UnicodeBlock block = Character.UnicodeBlock.of(peek); + if (block == Character.UnicodeBlock.HIGH_SURROGATES) { + skip(); + return this.text.substring(this.index - 2, this.index); + } + return String.valueOf(peek); + } + // Check url. + if (peek == 'h') { + if (peek(7).equals("http://") || peek(8).equals("https://")) { + return upToAny(HTTP); + } + } + int start = this.index; + boolean wasDigit = Character.isDigit(peek); + skip(); + while (!atEnd()) { + //peek = peekCodePoint(); + peek = peek(); + boolean isDigit = Character.isDigit(peek); + if (isWordSymbol(peek)) { + break; + } + // "-1" is ok + if (isSign && !isDigit) { + break; + } else { + // Allow "1.1", "1,000", "ab-ba", "ab_ba" + if (!Character.isLetter(peek) && !isDigit && (peek != '_')) { + if (wasDigit) { + if ((peek != '.') && (peek != ',') && (peek != '@')) { + break; + } + } else { + if ((peek != '-') && (peek != '_') && (peek != '@') && (peek != '.')) { + break; + } + } + } + } + wasDigit = isDigit; + skip(); + // Could have been "1.", "1.a" + if ((((peek == '.') && !Character.isLetter(peek())) || (peek == ',')) && !Character.isDigit(peek())) { + backup(); + break; + } + isSign = false; + } + return this.text.substring(start, this.index); + } + + public void skipWord() { + skipWhitespace(); + if (atEnd()) { + return; + } + if (TOKENS.indexOf(peek()) != -1) { + skip(); + } + // Check url. + if (peek() == 'h') { + if (peek(7).equals("http://")) { + skipToAny(WHITESPACE); + } + } + skipToAny(TOKENS); + } + + public String nextSentence() { + skipWhitespace(); + if (atEnd()) { + return null; + } + int start = this.index; + skipToAny(TERMINATORS, true); + while (!atEnd()) { + char peek = peek(); + boolean done = WHITESPACE.indexOf(peek) != -1; + if (done) { + if (current() != '.') { + break; + } + backup(); + String word = peekPreviousWord(); + skip(); + if (ABBREVIATIONS.contains(word.toLowerCase()) + || ((word.length() == 1) && (Character.isUpperCase(word.charAt(0))))) { + done = false; + } else { + break; + } + } else if (isWordSymbol(peek)) { + break; + } + skipToAny(TERMINATORS, true); + } + return this.text.substring(start, this.index); + } + + public String nextWhitespace() { + int start = this.index; + while (!atEnd() && (WHITESPACE.indexOf(peek()) != -1)) { + skip(); + } + return this.text.substring(start, this.index); + } + + public boolean skipWhitespace() { + boolean found = false; + while (!atEnd() && (Character.isWhitespace(peek()))) { + skip(); + found = true; + } + return found; + } + + public void backupWhitespace() { + while (!atStart() && (WHITESPACE.indexOf(current()) != -1)) { + backup(); + } + } + + public String nextLine() { + return upToAll("\n", true); + } + + public String currentLine() { + int position = this.index; + backupToAll("\n"); + String line = nextLine(); + this.index = position; + return line; + } + + public int currentLineNumber() { + int position = this.index; + this.index = 0; + int count = 0; + int last = this.index; + while (this.index < position) { + skipLine(); + if (this.index < position) { + count++; + } + if (this.index == last) { + break; + } + last = this.index; + } + this.index = position; + return count + 1; + } + + public int currentLineColumn() { + int position = this.index; + backupToAll("\n"); + int column = position - this.index; + this.index = position; + return column + 1; + } + + public void skipLine() { + skipToAll("\n", true); + } + + public int getPosition() { + return index; + } + + public void setPosition(int index) { + this.index = index; + } + + public String getText() { + return text; + } + + public String toString() { + return peek(text.length()); + } + } \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java index c0d7987..350a746 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java @@ -32,249 +32,249 @@ import java.util.regex.Pattern; * Utility class. */ public class Utils { - public static final Pattern httpRegex = Pattern.compile("\\b(?:https?|ftp|file):\\/\\/[a-z0-9-+&@#\\/%?=~_|!:,.;]*[a-z0-9-+&@#\\/%=~_|]", Pattern.CASE_INSENSITIVE); - public static final Pattern wwwRegex = Pattern.compile("((www\\.)[^\\s]+)", Pattern.CASE_INSENSITIVE); - public static final Pattern emailRegex = Pattern.compile("(([a-zA-Z0-9_\\-\\.]+)@[a-zA-Z_]+?(?:\\.[a-zA-Z]{2,6}))+", Pattern.CASE_INSENSITIVE); - - /** - * Includes http, www, images, video, audio, email address. - * - * @param text text - * @return Includes http, www, images, video, audio, email address. - */ - public static String linkHTML(String text) { - if (text == null || text.length() == 0) { - return ""; - } - boolean http = text.indexOf("http") != -1; - boolean www = text.indexOf("www.") != -1; - boolean email = text.indexOf("@") != -1; - if (!http && !www && !email) { - return text; - } - if (text.indexOf("<") != -1 && text.indexOf(">") != -1) { - return text; - } - if (http) { - Matcher matcher = httpRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String url = matcher.group(); - if (url.indexOf(".png") != -1 || url.indexOf(".jpg") != -1 || url.indexOf(".jpeg") != -1 || url.indexOf(".gif") != -1) { - url = ""; - } else if (url.indexOf(".mp4") != -1 || url.indexOf(".webm") != -1 || url.indexOf(".ogg") != -1) { - url = ""; - } else if (url.indexOf(".wav") != -1 || url.indexOf(".mp3") != -1) { - url = ""; - } else { - url = "" + url + ""; - } - matcher.appendReplacement(sb, url); - } - matcher.appendTail(sb); - text = sb.toString(); - } else if (www) { - Matcher matcher = wwwRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String url = matcher.group(); - matcher.appendReplacement(sb, "" + url + ""); - } - matcher.appendTail(sb); - text = sb.toString(); - } - - if (email) { - Matcher matcher = emailRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String address = matcher.group(); - matcher.appendReplacement(sb, "" + address + ""); - } - matcher.appendTail(sb); - text = sb.toString(); - } - return text; - } + public static final Pattern httpRegex = Pattern.compile("\\b(?:https?|ftp|file):\\/\\/[a-z0-9-+&@#\\/%?=~_|!:,.;]*[a-z0-9-+&@#\\/%=~_|]", Pattern.CASE_INSENSITIVE); + public static final Pattern wwwRegex = Pattern.compile("((www\\.)[^\\s]+)", Pattern.CASE_INSENSITIVE); + public static final Pattern emailRegex = Pattern.compile("(([a-zA-Z0-9_\\-\\.]+)@[a-zA-Z_]+?(?:\\.[a-zA-Z]{2,6}))+", Pattern.CASE_INSENSITIVE); + /** + * Includes http, www, images, video, audio, email address. + * + * @param text text + * @return Includes http, www, images, video, audio, email address. + */ + public static String linkHTML(String text) { + if (text == null || text.length() == 0) { + return ""; + } + boolean http = text.indexOf("http") != -1; + boolean www = text.indexOf("www.") != -1; + boolean email = text.indexOf("@") != -1; + if (!http && !www && !email) { + return text; + } + if (text.indexOf("<") != -1 && text.indexOf(">") != -1) { + return text; + } + if (http) { + Matcher matcher = httpRegex.matcher(text); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String url = matcher.group(); + if (url.indexOf(".png") != -1 || url.indexOf(".jpg") != -1 || url.indexOf(".jpeg") != -1 || url.indexOf(".gif") != -1) { + url = ""; + } else if (url.indexOf(".mp4") != -1 || url.indexOf(".webm") != -1 || url.indexOf(".ogg") != -1) { + url = ""; + } else if (url.indexOf(".wav") != -1 || url.indexOf(".mp3") != -1) { + url = ""; + } else { + url = "" + url + ""; + } + matcher.appendReplacement(sb, url); + } + matcher.appendTail(sb); + text = sb.toString(); + } else if (www) { + Matcher matcher = wwwRegex.matcher(text); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String url = matcher.group(); + matcher.appendReplacement(sb, "" + url + ""); + } + matcher.appendTail(sb); + text = sb.toString(); + } - /** - * Replace reserved HTML character with their HTML escape codes. - * - * @param html html - * @return Replace reserved HTML character with their HTML escape codes. - */ - public static String escapeHTML(String html) { - return html.replace("&", "&") - .replace("<", "<") - .replace(">", ">") - .replace("\"", """) - .replace("`", "`") - .replace("'", "'"); - } + if (email) { + Matcher matcher = emailRegex.matcher(text); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String address = matcher.group(); + matcher.appendReplacement(sb, "" + address + ""); + } + matcher.appendTail(sb); + text = sb.toString(); + } + return text; + } - /** - * Strip the HTML tags from the text. - * - * @param html html - * @return Strip the HTML tags from the text. - */ - public static String stripTags(String html) { - if (html == null) { - return ""; - } - String result = html; - if ((html.indexOf('<') != -1) && (html.indexOf('>') != -1)) { - StringWriter writer = new StringWriter(); - TextStream stream = new TextStream(html); - while (!stream.atEnd()) { - String text = stream.upTo('<'); - writer.write(text); - int position = stream.getPosition(); - stream.skip(); - String word = stream.nextWord(); - if (word != null) { - if (word.equals("p")) { - writer.write("\n\n"); - } else if (word.equals("br")) { - writer.write("\n"); - } else if (word.equals("div")) { - writer.write("\n"); - } - stream.skipTo('>'); - if (stream.atEnd()) { - stream.setPosition(position); - writer.write(stream.upToEnd()); - } else { - stream.skip(); - } - } - } - result = writer.toString(); - } - if (result.contains("&")) { - result = result.replace(""", "\""); - result = result.replace("`", "`"); - result = result.replace("'", "'"); - result = result.replace("@", "@"); - result = result.replace("=", "="); - result = result.replace("<", "<"); - result = result.replace(">", ">"); - } - return result; - } - /** - * displayTimestamp - * - * @param date date - * @return displayTimestamp - */ - public static String displayTimestamp(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar today = Calendar.getInstance(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { - writer.write("Today"); - } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { - writer.write("Yesterday"); - } else { - writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); - if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.YEAR))); - } - } - writer.write(", "); - writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - writer.write(":"); - if (calendar.get(Calendar.MINUTE) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - - return writer.toString(); - } + /** + * Replace reserved HTML character with their HTML escape codes. + * + * @param html html + * @return Replace reserved HTML character with their HTML escape codes. + */ + public static String escapeHTML(String html) { + return html.replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("`", "`") + .replace("'", "'"); + } - /** - * displayTime - * - * @param date date - * @return displayTime - */ - public static String displayTime(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - writer.write(":"); - if (calendar.get(Calendar.MINUTE) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - writer.write(":"); - if (calendar.get(Calendar.SECOND) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.SECOND))); - - return writer.toString(); - } + /** + * Strip the HTML tags from the text. + * + * @param html html + * @return Strip the HTML tags from the text. + */ + public static String stripTags(String html) { + if (html == null) { + return ""; + } + String result = html; + if ((html.indexOf('<') != -1) && (html.indexOf('>') != -1)) { + StringWriter writer = new StringWriter(); + TextStream stream = new TextStream(html); + while (!stream.atEnd()) { + String text = stream.upTo('<'); + writer.write(text); + int position = stream.getPosition(); + stream.skip(); + String word = stream.nextWord(); + if (word != null) { + if (word.equals("p")) { + writer.write("\n\n"); + } else if (word.equals("br")) { + writer.write("\n"); + } else if (word.equals("div")) { + writer.write("\n"); + } + stream.skipTo('>'); + if (stream.atEnd()) { + stream.setPosition(position); + writer.write(stream.upToEnd()); + } else { + stream.skip(); + } + } + } + result = writer.toString(); + } + if (result.contains("&")) { + result = result.replace(""", "\""); + result = result.replace("`", "`"); + result = result.replace("'", "'"); + result = result.replace("@", "@"); + result = result.replace("=", "="); + result = result.replace("<", "<"); + result = result.replace(">", ">"); + } + return result; + } - /** - * displayDate - * - * @param date date - * @return displayDate - */ - public static String displayDate(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar today = Calendar.getInstance(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { - writer.write("Today"); - } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { - writer.write("Yesterday"); - } else { - writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); - if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.YEAR))); - } - } - - return writer.toString(); - } + /** + * displayTimestamp + * + * @param date date + * @return displayTimestamp + */ + public static String displayTimestamp(Date date) { + if (date == null) { + return ""; + } + StringWriter writer = new StringWriter(); + Calendar today = Calendar.getInstance(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) + && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { + writer.write("Today"); + } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) + && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { + writer.write("Yesterday"); + } else { + writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); + writer.write(" "); + writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); + if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { + writer.write(" "); + writer.write(String.valueOf(calendar.get(Calendar.YEAR))); + } + } + writer.write(", "); + writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); + writer.write(":"); + if (calendar.get(Calendar.MINUTE) < 10) { + writer.write("0"); + } + writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - /** - * Capitalize the first character of the string. - * - * @param text text - * @return Capitalize the first character of the string. - */ - public static String capitalize(String text) { - if (text.length() == 0) { - return text; - } - return Character.toUpperCase(text.charAt(0)) + text.substring(1, text.length()); - } + return writer.toString(); + } + + /** + * displayTime + * + * @param date date + * @return displayTime + */ + public static String displayTime(Date date) { + if (date == null) { + return ""; + } + StringWriter writer = new StringWriter(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); + writer.write(":"); + if (calendar.get(Calendar.MINUTE) < 10) { + writer.write("0"); + } + writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); + writer.write(":"); + if (calendar.get(Calendar.SECOND) < 10) { + writer.write("0"); + } + writer.write(String.valueOf(calendar.get(Calendar.SECOND))); + + return writer.toString(); + } + + /** + * displayDate + * + * @param date date + * @return displayDate + */ + public static String displayDate(Date date) { + if (date == null) { + return ""; + } + StringWriter writer = new StringWriter(); + Calendar today = Calendar.getInstance(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) + && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { + writer.write("Today"); + } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) + && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { + writer.write("Yesterday"); + } else { + writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); + writer.write(" "); + writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); + if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { + writer.write(" "); + writer.write(String.valueOf(calendar.get(Calendar.YEAR))); + } + } + + return writer.toString(); + } + + /** + * Capitalize the first character of the string. + * + * @param text text + * @return Capitalize the first character of the string. + */ + public static String capitalize(String text) { + if (text.length() == 0) { + return text; + } + return Character.toUpperCase(text.charAt(0)) + text.substring(1, text.length()); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java index 1b2e369..83e57f1 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java @@ -23,14 +23,14 @@ package org.botlibre.sdk; * http://www.botlibre.com */ public class BOTlibreCredentials extends Credentials { - public static final String DOMAIN = "www.botlibre.com"; - public static final String APP = ""; - public static final String PATH = "/rest/api"; + public static final String DOMAIN = "www.botlibre.com"; + public static final String APP = ""; + public static final String PATH = "/rest/api"; - public BOTlibreCredentials(String applicationId) { - this.host = DOMAIN; - this.app = APP; - this.url = "https://" + DOMAIN + APP + PATH; - this.applicationId = applicationId; - } + public BOTlibreCredentials(String applicationId) { + this.host = DOMAIN; + this.app = APP; + this.url = "https://" + DOMAIN + APP + PATH; + this.applicationId = applicationId; + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java index dc730b7..2bf3c59 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java @@ -25,19 +25,19 @@ package org.botlibre.sdk; */ public class SDKException extends RuntimeException { - public SDKException(Exception exception) { - super(exception.getMessage(), exception); - } - - public SDKException(String message) { - super(message); - } - - public SDKException(String message, Exception exception) { - super(message, exception); - } - - public static SDKException parseFailure(Exception exception) { - throw new SDKException("parse failure", exception); - } + public SDKException(Exception exception) { + super(exception.getMessage(), exception); + } + + public SDKException(String message) { + super(message); + } + + public SDKException(String message, Exception exception) { + super(message, exception); + } + + public static SDKException parseFailure(Exception exception) { + throw new SDKException("parse failure", exception); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java index a113dbe..62ca2ab 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java @@ -26,63 +26,41 @@ import ohos.agp.components.Text; * Browse Ability for searching for a bot. */ public class BotSearchAbility extends SearchAbility implements SelectListener { - private int type = 0; - private Text sortSpin; - private Text restrictSpin; - private String[] sortSpinStr = new String[]{ - "connects", - "connects today", - "connects this week", - "connects this month", - "last connect", - "name", - "date", - "size", - "rank", - "wins", - "losses", - "thumbs up", - "thumbs down", - "stars" - }; - private String[] restrictSpinStr = new String[]{ - "", - "forkable", - "has website", - "has subdomain", - "external link", - "Platinum", - "Gold", - "Bronze" - }; - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void onStart(Intent intent) { - super.onStart(intent); + private int type = 0; + private String[] sortSpinStr = new String[]{ + "connects", + "connects today", + "connects this week", + "connects this month", + "last connect", + "name", + "date", + "size", + "rank", + "wins", + "losses", + "thumbs up", + "thumbs down", + "stars" + }; + private String[] restrictSpinStr = new String[]{ + "", + "forkable", + "has website", + "has subdomain", + "external link", + "Platinum", + "Gold", + "Bronze" + }; -// Checkbox checkbox = (Checkbox)findComponentById(ResourceTable.Id_imagesCheckBox); -// checkbox.setChecked(MainAbility.showImages); - -// sortSpin = (Text)findComponentById(ResourceTable.Id_sortSpin); -// sortSpin.setClickedListener(new Component.ClickedListener() { -// @Override -// public void onClick(Component component) { -// type = 0; -// SearchDialogBuilder.with(BotSearchAbility.this,sortSpinStr).setSelectInterface(BotSearchAbility.this); -// } -// }); -// -// restrictSpin = (Text) findComponentById(ResourceTable.Id_restrictSpin); -// restrictSpin.setClickedListener(new Component.ClickedListener() { -// @Override -// public void onClick(Component component) { -// type = 1; -// SearchDialogBuilder.with(BotSearchAbility.this,restrictSpinStr).setSelectInterface(BotSearchAbility.this); -// } -// }); - } - - public String getType() { - return "Bot"; - } + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + public String getType() { + return "Bot"; + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java index 6482acb..20d94d8 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java @@ -23,11 +23,11 @@ package org.botlibre.sdk.ability; */ public enum EmotionalState { - NONE, - LOVE, LIKE, DISLIKE, HATE, - RAGE, ANGER, CALM, SERENE, - ECSTATIC, HAPPY, SAD, CRYING, - PANIC, AFRAID, CONFIDENT, COURAGEOUS, - SURPRISE, BORED, - LAUGHTER, SERIOUS; + NONE, + LOVE, LIKE, DISLIKE, HATE, + RAGE, ANGER, CALM, SERENE, + ECSTATIC, HAPPY, SAD, CRYING, + PANIC, AFRAID, CONFIDENT, COURAGEOUS, + SURPRISE, BORED, + LAUGHTER, SERIOUS; } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index 24ff09c..1875916 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java @@ -30,45 +30,45 @@ import org.botlibre.sdk.config.UserConfig; */ public class LoginAbility extends LibreAbility implements Component.ClickedListener { - @Override - public void onStart(Intent intent) { - super.onStart(intent); + @Override + public void onStart(Intent intent) { + super.onStart(intent); // setContentView(R.layout.Ability_login); - super.setUIContent(ResourceTable.Layout_ability_login); + super.setUIContent(ResourceTable.Layout_ability_login); - Button connectButton = (Button)findComponentById(ResourceTable.Id_connectButton); - connectButton.setClickedListener(this); - Button signUpButton = (Button)findComponentById(ResourceTable.Id_signUpButton); - signUpButton.setClickedListener(this); - } - - /** - * Start a chat session with the selected instance and the user. - */ - public void connect() { - TextField text = (TextField) findComponentById(ResourceTable.Id_userText); + Button connectButton = (Button) findComponentById(ResourceTable.Id_connectButton); + connectButton.setClickedListener(this); + Button signUpButton = (Button) findComponentById(ResourceTable.Id_signUpButton); + signUpButton.setClickedListener(this); + } + + /** + * Start a chat session with the selected instance and the user. + */ + public void connect() { + TextField text = (TextField) findComponentById(ResourceTable.Id_userText); String user = text.getText().toString().trim(); text = (TextField) findComponentById(ResourceTable.Id_passwordText); String password = text.getText().toString().trim(); - - UserConfig config = new UserConfig(); - config.user = user; - config.password = password; + + UserConfig config = new UserConfig(); + config.user = user; + config.password = password; } - - public void signUp() { - terminateAbility(); - - startOpenAbility(this,CreateUserAbility.class.getName()); - } - @Override - public void onClick(Component component) { - if(component.getId() == ResourceTable.Id_connectButton){//登录 - connect(); - } - if(component.getId() == ResourceTable.Id_signUpButton){// 注册 - signUp(); - } - } + public void signUp() { + terminateAbility(); + + startOpenAbility(this, CreateUserAbility.class.getName()); + } + + @Override + public void onClick(Component component) { + if (component.getId() == ResourceTable.Id_connectButton) {//登录 + connect(); + } + if (component.getId() == ResourceTable.Id_signUpButton) {// 注册 + signUp(); + } + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java index be08f49..1e1a08d 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/MicConfigAbility.java @@ -429,6 +429,7 @@ public class MicConfigAbility extends LibreAbility implements AsrListener { terminateAbility(); super.onBackPressed(); } + public boolean deleteRecordedFile(File outputFile) { boolean deleted = false; if (outputFile.exists()) { diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java index 41d7ff8..90e7bd0 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/SearchAbility.java @@ -51,243 +51,243 @@ import java.util.Optional; * @since 2021-04-16 */ public abstract class SearchAbility extends LibreAbility implements SelectListener { - final static int TAGTEXT = 3,CATTEXT = 4; - - private Text sortSpin,restrictSpin; - private int type = 0; - private RadioButton publicRadio; - private RadioButton radio; - private RadioButton personalRadio; - private BrowseConfig config; - private Button browseButton; - private Button menuButton; - private Text contentRating; - private String[] sortSpinStr = new String[]{ - "connects", - "connects today", - "connects this week", - "connects this month", - "last connect", - "name", - "date", - "thumbs up", - "thumbs down", - "stars" - }; - private String[] restrictSpinStr = new String[]{ - "", - "has website", - "has subdomain", - "external link", - "Diamond", - "Platinum", - "Gold", - "Bronze" - }; - - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_search); - browseButton = (Button) findComponentById(ResourceTable.Id_browseButton); - menuButton = (Button) findComponentById(ResourceTable.Id_menuButton); - - Checkbox checkbox = (Checkbox) findComponentById(ResourceTable.Id_imagesCheckBox); - StateElement stateElement = new StateElement(); - stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, ResUtils.getPixelMapDrawable(this - , ResourceTable.Media_checkbox_checked)); - stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, ResUtils.getPixelMapDrawable(this - , ResourceTable.Media_checkbox_normal)); - checkbox.setButtonElement(stateElement); - checkbox.setChecked(MainAbility.isShowImages()); - - publicRadio = (RadioButton) findComponentById(ResourceTable.Id_publicRadio); - publicRadio.setChecked(true); - config = new BrowseConfig(); - if (publicRadio.isChecked()) { - config.typeFilter = "Public"; - } - config.typeFilter = "Public"; - radio = (RadioButton) findComponentById(ResourceTable.Id_privateRadio); - if (radio.isChecked()) { - config.typeFilter = "Private"; - } - personalRadio = (RadioButton) findComponentById(ResourceTable.Id_personalRadio); - if (radio.isChecked()) { - config.typeFilter = "Personal"; - } - - publicRadio.setButtonElement(setSelect()); - radio.setButtonElement(setSelect()); - personalRadio.setButtonElement(setSelect()); - publicRadio.setClickedListener(sampleOnClickListener); - radio.setClickedListener(sampleOnClickListener); - personalRadio.setClickedListener(sampleOnClickListener); - - Text title = (Text) findComponentById(ResourceTable.Id_title); - title.setText("Search " + getType() + "s"); - sortSpin = (Text)findComponentById(ResourceTable.Id_sortSpin); - sortSpin.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - type = 0; - SearchDialogBuilder.with(SearchAbility.this,sortSpinStr).setSelectInterface(SearchAbility.this); - } - }); - - restrictSpin = (Text) findComponentById(ResourceTable.Id_restrictSpin); - restrictSpin.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - type = 1; - SearchDialogBuilder.with(SearchAbility.this,restrictSpinStr).setSelectInterface(SearchAbility.this); - } - }); - - - contentRating = (Text) findComponentById(ResourceTable.Id_ContentRatingSpin); - - contentRating.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - type = 2; - SearchDialogBuilder.with(SearchAbility.this,MainAbility.getContentRatings()).setSelectInterface(SearchAbility.this); - } - }); - - browseButton.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - browse(); - } - }); - - menuButton.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - menu(); - } - }); - } - - @Override - protected void onAbilityResult(int requestCode, int resultCode, Intent data) { - // TODO Auto-generated method stub - super.onAbilityResult(requestCode, resultCode, data); - switch(requestCode){ - case TAGTEXT: - break; - case CATTEXT: - break; - } - } - - - - - private void browse() { - Preferences editor = PreferencesUtils.getPreferences(MainAbility.getCurrent()); - editor.putString("contentRating", MainAbility.getContentRating()); - editor.flushSync(); - - TextField tagText = (TextField)findComponentById(ResourceTable.Id_tagsText); - config.tag = (String)tagText.getText().toString(); - TextField categoryText = (TextField)findComponentById(ResourceTable.Id_categoriesText); - config.category = (String)categoryText.getText().toString(); - TextField filterEdit = (TextField)findComponentById(ResourceTable.Id_filterText); - config.filter = filterEdit.getText().toString(); - Checkbox checkbox = (Checkbox)findComponentById(ResourceTable.Id_imagesCheckBox); - MainAbility.setShowImages(checkbox.isChecked()); - config.type = getType(); - } - private StateElement setSelect() { - StateElement stateElement = new StateElement(); - stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, - ResUtils.getPixelMapDrawable(getContext(), ResourceTable.Media_radioselect)); - stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, - ResUtils.getPixelMapDrawable(getContext(), ResourceTable.Media_radionormal)); - - return stateElement; - } - private final Component.ClickedListener sampleOnClickListener = new RadioButton.ClickedListener() { - @Override - public void onClick(Component component) { - if (publicRadio.isChecked()) { - config.typeFilter = "Public"; - } else if (radio.isChecked()) { - config.typeFilter = "Private"; - } else if (personalRadio.isChecked()) { - config.typeFilter = "Personal"; - } - } - }; - - public abstract String getType(); - - private void menu() { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(this); - DisplayAttributes displayAttributes = display.get().getAttributes(); - - PopupDialog menuDialog = new PopupDialog(this, null); - DirectionalLayout menuComponent = (DirectionalLayout) LayoutScatter.getInstance(this) - .parse(ResourceTable.Layout_search_menu, null, false); - menuDialog.setCustomComponent(menuComponent); - menuDialog.showOnCertainPosition(1,displayAttributes.width,-displayAttributes.width + 150); - menuDialog.setAutoClosable(true); - menuDialog.setAlignment(LayoutAlignment.RIGHT|LayoutAlignment.TOP); - menuDialog.show(); - - Text mybots = (Text) menuComponent.findComponentById(ResourceTable.Id_mybots); - mybots.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - } - }); - - Text browsefeatured = (Text) menuComponent.findComponentById(ResourceTable.Id_browsefeatured); - browsefeatured.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - browseFeatured(); - menuDialog.destroy(); - } - }); - - Text browsecategories = (Text) menuComponent.findComponentById(ResourceTable.Id_browsecategories); - browsecategories.setClickedListener(new Component.ClickedListener() { - @Override - public void onClick(Component component) { - browseCategories(); - menuDialog.destroy(); - } - }); - } - - private void browseFeatured() { - BrowseConfig config = new BrowseConfig(); - config.type = getType(); - config.typeFilter = "Featured"; - config.contentRating = MainAbility.getContentRating(); - } - - private void browseCategories() { - } - - @Override - public void selectItem(String select) { - if(type == 0){ - sortSpin.setText(select); - config.sort = select; - } else if(type == 1){ - restrictSpin.setText(select); - config.restrict = select; - } else if(type == 2){ - contentRating.setText(select); - config.contentRating = select; - } - - } + final static int TAGTEXT = 3, CATTEXT = 4; + + private Text sortSpin, restrictSpin; + private int type = 0; + private RadioButton publicRadio; + private RadioButton radio; + private RadioButton personalRadio; + private BrowseConfig config; + private Button browseButton; + private Button menuButton; + private Text contentRating; + private String[] sortSpinStr = new String[]{ + "connects", + "connects today", + "connects this week", + "connects this month", + "last connect", + "name", + "date", + "thumbs up", + "thumbs down", + "stars" + }; + private String[] restrictSpinStr = new String[]{ + "", + "has website", + "has subdomain", + "external link", + "Diamond", + "Platinum", + "Gold", + "Bronze" + }; + + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_search); + browseButton = (Button) findComponentById(ResourceTable.Id_browseButton); + menuButton = (Button) findComponentById(ResourceTable.Id_menuButton); + + Checkbox checkbox = (Checkbox) findComponentById(ResourceTable.Id_imagesCheckBox); + StateElement stateElement = new StateElement(); + stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, ResUtils.getPixelMapDrawable(this + , ResourceTable.Media_checkbox_checked)); + stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, ResUtils.getPixelMapDrawable(this + , ResourceTable.Media_checkbox_normal)); + checkbox.setButtonElement(stateElement); + checkbox.setChecked(MainAbility.isShowImages()); + + publicRadio = (RadioButton) findComponentById(ResourceTable.Id_publicRadio); + publicRadio.setChecked(true); + config = new BrowseConfig(); + if (publicRadio.isChecked()) { + config.typeFilter = "Public"; + } + config.typeFilter = "Public"; + radio = (RadioButton) findComponentById(ResourceTable.Id_privateRadio); + if (radio.isChecked()) { + config.typeFilter = "Private"; + } + personalRadio = (RadioButton) findComponentById(ResourceTable.Id_personalRadio); + if (radio.isChecked()) { + config.typeFilter = "Personal"; + } + + publicRadio.setButtonElement(setSelect()); + radio.setButtonElement(setSelect()); + personalRadio.setButtonElement(setSelect()); + publicRadio.setClickedListener(sampleOnClickListener); + radio.setClickedListener(sampleOnClickListener); + personalRadio.setClickedListener(sampleOnClickListener); + + Text title = (Text) findComponentById(ResourceTable.Id_title); + title.setText("Search " + getType() + "s"); + sortSpin = (Text) findComponentById(ResourceTable.Id_sortSpin); + sortSpin.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + type = 0; + SearchDialogBuilder.with(SearchAbility.this, sortSpinStr).setSelectInterface(SearchAbility.this); + } + }); + + restrictSpin = (Text) findComponentById(ResourceTable.Id_restrictSpin); + restrictSpin.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + type = 1; + SearchDialogBuilder.with(SearchAbility.this, restrictSpinStr).setSelectInterface(SearchAbility.this); + } + }); + + + contentRating = (Text) findComponentById(ResourceTable.Id_ContentRatingSpin); + + contentRating.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + type = 2; + SearchDialogBuilder.with(SearchAbility.this, MainAbility.getContentRatings()).setSelectInterface(SearchAbility.this); + } + }); + + browseButton.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + browse(); + } + }); + + menuButton.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + menu(); + } + }); + } + + @Override + protected void onAbilityResult(int requestCode, int resultCode, Intent data) { + // TODO Auto-generated method stub + super.onAbilityResult(requestCode, resultCode, data); + switch (requestCode) { + case TAGTEXT: + break; + case CATTEXT: + break; + } + } + + + private void browse() { + Preferences editor = PreferencesUtils.getPreferences(MainAbility.getCurrent()); + editor.putString("contentRating", MainAbility.getContentRating()); + editor.flushSync(); + + TextField tagText = (TextField) findComponentById(ResourceTable.Id_tagsText); + config.tag = (String) tagText.getText().toString(); + TextField categoryText = (TextField) findComponentById(ResourceTable.Id_categoriesText); + config.category = (String) categoryText.getText().toString(); + TextField filterEdit = (TextField) findComponentById(ResourceTable.Id_filterText); + config.filter = filterEdit.getText().toString(); + Checkbox checkbox = (Checkbox) findComponentById(ResourceTable.Id_imagesCheckBox); + MainAbility.setShowImages(checkbox.isChecked()); + config.type = getType(); + } + + private StateElement setSelect() { + StateElement stateElement = new StateElement(); + stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, + ResUtils.getPixelMapDrawable(getContext(), ResourceTable.Media_radioselect)); + stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, + ResUtils.getPixelMapDrawable(getContext(), ResourceTable.Media_radionormal)); + + return stateElement; + } + + private final Component.ClickedListener sampleOnClickListener = new RadioButton.ClickedListener() { + @Override + public void onClick(Component component) { + if (publicRadio.isChecked()) { + config.typeFilter = "Public"; + } else if (radio.isChecked()) { + config.typeFilter = "Private"; + } else if (personalRadio.isChecked()) { + config.typeFilter = "Personal"; + } + } + }; + + public abstract String getType(); + + private void menu() { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(this); + DisplayAttributes displayAttributes = display.get().getAttributes(); + + PopupDialog menuDialog = new PopupDialog(this, null); + DirectionalLayout menuComponent = (DirectionalLayout) LayoutScatter.getInstance(this) + .parse(ResourceTable.Layout_search_menu, null, false); + menuDialog.setCustomComponent(menuComponent); + menuDialog.showOnCertainPosition(1, displayAttributes.width, -displayAttributes.width + 150); + menuDialog.setAutoClosable(true); + menuDialog.setAlignment(LayoutAlignment.RIGHT | LayoutAlignment.TOP); + menuDialog.show(); + + Text mybots = (Text) menuComponent.findComponentById(ResourceTable.Id_mybots); + mybots.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + } + }); + + Text browsefeatured = (Text) menuComponent.findComponentById(ResourceTable.Id_browsefeatured); + browsefeatured.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + browseFeatured(); + menuDialog.destroy(); + } + }); + + Text browsecategories = (Text) menuComponent.findComponentById(ResourceTable.Id_browsecategories); + browsecategories.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + browseCategories(); + menuDialog.destroy(); + } + }); + } + + private void browseFeatured() { + BrowseConfig config = new BrowseConfig(); + config.type = getType(); + config.typeFilter = "Featured"; + config.contentRating = MainAbility.getContentRating(); + } + + private void browseCategories() { + } + + @Override + public void selectItem(String select) { + if (type == 0) { + sortSpin.setText(select); + config.sort = select; + } else if (type == 1) { + restrictSpin.setText(select); + config.restrict = select; + } else if (type == 2) { + contentRating.setText(select); + config.contentRating = select; + } + + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java index 780d552..ec2ae66 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java @@ -19,46 +19,45 @@ package org.botlibre.sdk.ability.actions; - import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.ability.Ability; import ohos.app.Context; public class HttpCreateUserAction extends HttpUIResultAction { - UserConfig config; - - public HttpCreateUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - doInBackground(); - } + UserConfig config; -// @Override - protected void doInBackground() { - try { - this.config = MainAbility.getConnection().create(ability,this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } + public HttpCreateUserAction(Ability ability, UserConfig config) { + super(ability); + this.config = config; + doInBackground(); + } - if (this.exception != null) { - return; - } - try { - MainAbility.setUser(config); - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - removeDialog(); - return; - } + // @Override + protected void doInBackground() { + try { + this.config = MainAbility.getConnection().create(ability, this.config); + } catch (Exception exception) { + this.exception = exception; + removeDialog(); + return; + } + + if (this.exception != null) { + return; + } + try { + MainAbility.setUser(config); + this.ability.terminateAbility(); + } catch (Exception error) { + this.exception = error; + removeDialog(); + return; + } - } + } - public void onPostExecute(String xml) { + public void onPostExecute(String xml) { } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java index 8016ed7..d1f5b21 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java @@ -32,104 +32,88 @@ import org.botlibre.sdk.util.PreferencesUtils; import static org.botlibre.sdk.MainAbility.*; public class HttpFetchAction extends HttpUIResultAction { - WebMediumConfig config; - boolean launch; + WebMediumConfig config; + boolean launch; - public HttpFetchAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - public HttpFetchAction(Ability ability, WebMediumConfig config, boolean launch) { - super(ability); - this.config = config; - this.launch = launch; - doInBackground(); - } + public HttpFetchAction(Ability ability, WebMediumConfig config) { + super(ability); + this.config = config; + } - public void doInBackground(){ - loadingDialog(); - try { - this.config = getConnection().fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - onPostExecute(); - } + public HttpFetchAction(Ability ability, WebMediumConfig config, boolean launch) { + super(ability); + this.config = config; + this.launch = launch; + doInBackground(); + } -// @Override -// protected String doInBackground(Void... params) { -// try { -// -// } catch (Exception exception) { -// this.exception = exception; -// } -// return ""; -// } - -// public void superOnPostExecute(String xml) { -// super.onPostExecute(xml); -// } + public void doInBackground() { + loadingDialog(); + try { + this.config = getConnection().fetch(this.config); + } catch (Exception exception) { + this.exception = exception; + removeDialog(); + return; + } + onPostExecute(); + } - @SuppressWarnings("rawtypes") + @SuppressWarnings("rawtypes") // @Override - public void onPostExecute() { + public void onPostExecute() { // super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - setInstance(config); + if (this.exception != null) { + return; + } + try { + setInstance(config); + + Preferences cookies = PreferencesUtils.getPreferences(this.ability); + cookies.putString(this.config.getType(), this.config.name); + cookies.flushSync(); + + Class childAbility = getAbility(this.config); + if (this.launch && !this.config.isExternal) { + if (this.config instanceof ChannelConfig) { + } else if (this.config instanceof InstanceConfig) { + } else if (this.config instanceof DomainConfig) { + getConnection().setDomain((DomainConfig) this.config); + setDomain((DomainConfig) this.config); + setTags(null); + setCategories(null); + setForumTags(null); + setForumCategories(null); + setChannelTags(null); + setChannelCategories(null); + setDomainTags(null); + setDomainCategories(null); + setGraphicTags(null); + setGraphicCategories(null); + + setType(getDefaultType()); - Preferences cookies= PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), this.config.name); - cookies.flushSync(); + startOpenAbility(this.ability, MainAbility.class.getName()); + return; + } else if (this.config instanceof ForumConfig) { + BrowseConfig config = new BrowseConfig(); - Class childAbility = getABility(this.config); - if (this.launch && !this.config.isExternal) { - if (this.config instanceof ChannelConfig) { -// childAbility = LiveChatAbility.class; - } else if (this.config instanceof InstanceConfig) { -// childAbility = ChatAbility.class; - } else if (this.config instanceof DomainConfig) { - getConnection().setDomain((DomainConfig)this.config); - setDomain((DomainConfig)this.config); - setTags(null); - setCategories(null); - setForumTags(null); - setForumCategories(null); - setChannelTags(null); - setChannelCategories(null); - setDomainTags(null); - setDomainCategories(null); - setGraphicTags(null); - setGraphicCategories(null); - - setType(getDefaultType()); + config.typeFilter = "Public"; + config.type = "Post"; + config.instance = getInstance().id; + config.sort = "date"; + return; + } + } else { + if (this.config instanceof InstanceConfig) { + } + } + startOpenAbility(this.ability, childAbility.getName()); + } catch (Exception error) { + this.exception = error; + error(this.exception.getMessage(), this.exception, this.ability); + return; + } + } - startOpenAbility(this.ability,MainAbility.class.getName()); - return; - } else if (this.config instanceof ForumConfig) { - BrowseConfig config = new BrowseConfig(); - - config.typeFilter = "Public"; - config.type = "Post"; - config.instance = getInstance().id; - config.sort = "date"; - return; - } - } else { - if (this.config instanceof InstanceConfig) { - } - } - startOpenAbility(this.ability,childAbility.getName()); - } catch (Exception error) { - this.exception = error; - error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java index dc18ddc..9f857eb 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java @@ -21,32 +21,31 @@ package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.ability.Ability; + public class HttpFlagUserAction extends HttpUIAction { - UserConfig config; + UserConfig config; + + public HttpFlagUserAction(Ability ability, UserConfig config) { + super(ability); + this.config = config; + } - public HttpFlagUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - } + @Override + protected String doInBackground(Void... params) { + try { + MainAbility.getConnection().flag(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + } - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - //MainAbility.viewUser.isFlagged = true; - //this.Ability.findViewById(R.id.flaggedLabel).setVisibility(View.VISIBLE); - } - } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java index 42ea5ac..c597e18 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java @@ -26,36 +26,35 @@ import org.botlibre.sdk.config.AvatarMedia; import ohos.aafwk.ability.Ability; public class HttpGetAvatarMediaAction extends HttpUIAction { - AvatarConfig config; - List instances; - boolean finish = false; + AvatarConfig config; + List instances; + boolean finish = false; - public HttpGetAvatarMediaAction(Ability ability, AvatarConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - } + public HttpGetAvatarMediaAction(Ability ability, AvatarConfig config, boolean finish) { + super(ability); + this.config = config; + this.finish = finish; + } - @Override - protected String doInBackground(Void... params) { - try { - this.instances = MainAbility.getConnection().getAvatarMedia(config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + protected String doInBackground(Void... params) { + try { + this.instances = MainAbility.getConnection().getAvatarMedia(config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setAvatarMedias(instances); - if (this.finish) { - this.ability.terminateAbility(); - } -// startOpenAbility(this.ability, AvatarEditorAbility.class.getName()); - } + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + MainAbility.setAvatarMedias(instances); + if (this.finish) { + this.ability.terminateAbility(); + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java index 584fc19..b2dd10c 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java @@ -24,39 +24,39 @@ import org.botlibre.sdk.config.LearningConfig; import ohos.aafwk.ability.Ability; public class HttpGetLearningAction extends HttpUIAction { - InstanceConfig config; - LearningConfig learning; - - public HttpGetLearningAction(Ability Ability, InstanceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.learning = MainAbility.getConnection().getLearning(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.setLearning(learning); - + InstanceConfig config; + LearningConfig learning; + + public HttpGetLearningAction(Ability Ability, InstanceConfig config) { + super(Ability); + this.config = config; + } + + @Override + protected String doInBackground(Void... params) { + try { + this.learning = MainAbility.getConnection().getLearning(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } + + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + try { + MainAbility.setLearning(learning); + // ((LearningAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - + } catch (Exception error) { + this.exception = error; + MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + return; + } + } + } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java index b6be9cf..5152e0f 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java @@ -29,13 +29,13 @@ import java.util.List; public class HttpGetTemplatesAction extends HttpAction { - public HttpGetTemplatesAction(Ability Ability) { - super(Ability); - - } - - @Override - protected String doInBackground(Void... params) { - return ""; - } + public HttpGetTemplatesAction(Ability Ability) { + super(Ability); + + } + + @Override + protected String doInBackground(Void... params) { + return ""; + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java index a8a52bb..43ef52f 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java @@ -32,41 +32,41 @@ import ohos.agp.window.service.DisplayManager; import java.util.Optional; public abstract class HttpUIAction extends HttpAction { - protected CommonDialog dialog; + protected CommonDialog dialog; - public HttpUIAction(Ability Ability) { - super(Ability); - } + public HttpUIAction(Ability Ability) { + super(Ability); + } - // 加载 - public void loadingDialog(){ - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } + // 加载 + public void loadingDialog() { + try { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); + DisplayAttributes displayAttributes = display.get().getAttributes(); + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). + parse(ResourceTable.Layout_loading_dialog, + null, false); + this.dialog = new CommonDialog(this.ability); + this.dialog.setContentCustomComponent(layout); + this.dialog.setAutoClosable(false); + this.dialog.setSize(displayAttributes.width - 100, 150); + this.dialog.show(); + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); + } + } - public void removeDialog(){ - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1,this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } + public void removeDialog() { + try { + if (this.dialog != null) { + this.dialog.destroy(); + } + if (this.exception != null) { + MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); + } + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java index c952ff7..b79ac22 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java @@ -33,45 +33,41 @@ import ohos.agp.window.service.DisplayManager; import java.util.Optional; public abstract class HttpUIResultAction extends HttpResultAction { - protected CommonDialog dialog; + protected CommonDialog dialog; - public HttpUIResultAction(Ability Ability) { - super(Ability); - } + public HttpUIResultAction(Ability Ability) { + super(Ability); + } - // 加载 - public void loadingDialog(){ - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } + // 加载 + public void loadingDialog() { + try { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); + DisplayAttributes displayAttributes = display.get().getAttributes(); + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). + parse(ResourceTable.Layout_loading_dialog, + null, false); + this.dialog = new CommonDialog(this.ability); + this.dialog.setContentCustomComponent(layout); + this.dialog.setAutoClosable(false); + this.dialog.setSize(displayAttributes.width - 100, 150); + this.dialog.show(); + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); + } + } - public void removeDialog(){ - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { -// if(!exception.toString().equals("403")) { -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// } else { - MainAbility.errorInfo(1,ResUtils.getString(ability,ResourceTable.String_exception), this.exception, this.ability); -// } - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } + public void removeDialog() { + try { + if (this.dialog != null) { + this.dialog.destroy(); + } + if (this.exception != null) { + MainAbility.errorInfo(1, ResUtils.getString(ability, ResourceTable.String_exception), this.exception, this.ability); + } + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java index 89f91d0..2e498d3 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java @@ -31,29 +31,29 @@ import ohos.data.preferences.Preferences; import java.util.ArrayList; /** - * used for selecting an offline avatar. + * used for selecting an offline avatar. */ public class AvatarSelection extends Ability { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_list_view); - final int [] imges = {}; - final String [] names = {}; - ((Text) findComponentById(ResourceTable.Id_theTitle)).setText("Select Avatar"); - ArrayList items = new ArrayList(); - for (int i = 0; i < names.length; i++) { - items.add(new OfflineTemplateConfig(imges[i],names[i],null,null)); - } - - } - - public static void saveSelectedAvatar(String nameOfAvatar) { - MainAbility.setNameOfAvatar(nameOfAvatar); - Preferences cookies = PreferencesUtils.getPreferences(MainAbility.getCurrent()); - cookies.putString("nameOfAvatar", nameOfAvatar); - cookies.flushSync(); - } + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_list_view); + final int[] imges = {}; + final String[] names = {}; + ((Text) findComponentById(ResourceTable.Id_theTitle)).setText("Select Avatar"); + ArrayList items = new ArrayList(); + for (int i = 0; i < names.length; i++) { + items.add(new OfflineTemplateConfig(imges[i], names[i], null, null)); + } + + } + + public static void saveSelectedAvatar(String nameOfAvatar) { + MainAbility.setNameOfAvatar(nameOfAvatar); + Preferences cookies = PreferencesUtils.getPreferences(MainAbility.getCurrent()); + cookies.putString("nameOfAvatar", nameOfAvatar); + cookies.flushSync(); + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java index 7d0c9ee..f6a3c42 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java @@ -8,37 +8,37 @@ import java.io.StringWriter; * DTO for XML chat war config. */ public class ChatWarConfig extends Config { - public String winner; - public String looser; - public String topic; - public String secret; - - public ChatWarConfig() { - - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String winner; + public String looser; + public String topic; + public String secret; + + public ChatWarConfig() { + + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java index 7be2f53..d5bfb5a 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java @@ -6,32 +6,32 @@ import org.botlibre.sdk.config.InstanceConfig; import ohos.aafwk.ability.Ability; public class HttpChatWarAction extends HttpUIAction { - ChatWarConfig config; - InstanceConfig instance; + ChatWarConfig config; + InstanceConfig instance; - public HttpChatWarAction(Ability ability, ChatWarConfig config) { - super(ability); - this.config = config; - } + public HttpChatWarAction(Ability ability, ChatWarConfig config) { + super(ability); + this.config = config; + } - @Override - protected String doInBackground(Void... params) { - try { - InstanceConfig instance = new InstanceConfig(); - this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + protected String doInBackground(Void... params) { + try { + InstanceConfig instance = new InstanceConfig(); + this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } + + @Override + protected void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + MainAbility.setInstance(instance); + } - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setInstance(instance); - } - } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java index 5864f9a..4fe4f10 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java @@ -76,7 +76,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi if (MainAbility.isBrowsing()) { if ((MainAbility.getInstance() instanceof InstanceConfig)) { if (this.browsing == 0) { - setBot1((InstanceConfig)MainAbility.getInstance()); + setBot1((InstanceConfig) MainAbility.getInstance()); Preferences cookies = PreferencesUtils.getPreferences(MainAbility.getCurrent()); cookies.putString(bot1.getType(), bot1.name); cookies.flushSync(); @@ -213,7 +213,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi * getBot1 * * @return InstanceConfig - * */ + */ public static InstanceConfig getBot1() { return bot1; } @@ -222,7 +222,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi * setBot1 * * @param bot1 InstanceConfig - * */ + */ public static void setBot1(InstanceConfig bot1) { StartWarAbility.bot1 = bot1; } @@ -231,7 +231,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi * getBot2 * * @return InstanceConfig - * */ + */ public static InstanceConfig getBot2() { return bot2; } @@ -240,7 +240,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi * setBot2 * * @param bot2 InstanceConfig - * */ + */ public static void setBot2(InstanceConfig bot2) { StartWarAbility.bot2 = bot2; } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java index 8a1ac5e..411f57b 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java @@ -29,101 +29,106 @@ import org.w3c.dom.Element; * The media is the short URL to the media file on the server. */ public class AvatarMedia extends Config { - public String mediaId; - public String name; - public String media; - public String emotions; - public String actions; - public String poses; - public boolean hd; - public boolean talking; - - public void parseXML(Element element) { - super.parseXML(element); - - this.mediaId = element.getAttribute("mediaId"); - this.name = element.getAttribute("name"); - this.type = element.getAttribute("type"); - this.media = element.getAttribute("media"); - this.emotions = element.getAttribute("emotions"); - this.actions = element.getAttribute("actions"); - this.poses = element.getAttribute("poses"); - this.hd = Boolean.valueOf(element.getAttribute("hd")); - this.talking = Boolean.valueOf(element.getAttribute("talking")); - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public boolean getHD() { - return hd; - } - public boolean isImage() { - return this.type.contains("image") || this.type.isEmpty(); - } - - public boolean isVideo() { - return this.type != null && this.type.indexOf("video") != -1; - } - - public boolean isAudio() { - return this.type != null && this.type.indexOf("audio") != -1; - } - public String getType() { - return type; - } - public String getEmotions() { - return emotions; - } - - public void setEmotions(String emotions) { - this.emotions = emotions; - } - public String getActions() { - return actions; - } - - public String getPoses() { - return poses; - } - - public void setPoses(String poses) { - this.poses = poses; - } - - public void setActions(String actions) { - this.actions = actions; - } - public boolean getTalking() { - return talking; - } - - public void setTalking(boolean talking) { - this.talking = talking; - } + public String mediaId; + public String name; + public String media; + public String emotions; + public String actions; + public String poses; + public boolean hd; + public boolean talking; + + public void parseXML(Element element) { + super.parseXML(element); + + this.mediaId = element.getAttribute("mediaId"); + this.name = element.getAttribute("name"); + this.type = element.getAttribute("type"); + this.media = element.getAttribute("media"); + this.emotions = element.getAttribute("emotions"); + this.actions = element.getAttribute("actions"); + this.poses = element.getAttribute("poses"); + this.hd = Boolean.valueOf(element.getAttribute("hd")); + this.talking = Boolean.valueOf(element.getAttribute("talking")); + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public boolean getHD() { + return hd; + } + + public boolean isImage() { + return this.type.contains("image") || this.type.isEmpty(); + } + + public boolean isVideo() { + return this.type != null && this.type.indexOf("video") != -1; + } + + public boolean isAudio() { + return this.type != null && this.type.indexOf("audio") != -1; + } + + public String getType() { + return type; + } + + public String getEmotions() { + return emotions; + } + + public void setEmotions(String emotions) { + this.emotions = emotions; + } + + public String getActions() { + return actions; + } + + public String getPoses() { + return poses; + } + + public void setPoses(String poses) { + this.poses = poses; + } + + public void setActions(String actions) { + this.actions = actions; + } + + public boolean getTalking() { + return talking; + } + + public void setTalking(boolean talking) { + this.talking = talking; + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java index 0078f54..04f45d4 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java @@ -28,51 +28,51 @@ import java.io.StringWriter; * This object can be converted to and from XML for usage with the web API. */ public class AvatarMessage extends Config { - public String message; - public String avatar; - public String emote; - public String action; - public String pose; - public boolean speak; - public String voice; - public String format; - public boolean hd; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.message != null) { - writer.write(""); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } + public String message; + public String avatar; + public String emote; + public String action; + public String pose; + public boolean speak; + public String voice; + public String format; + public boolean hd; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.message != null) { + writer.write(""); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java index 5e672e1..64ff99b 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java @@ -27,31 +27,31 @@ import org.w3c.dom.Element; * DTO for XML bot mode config. */ public class BotModeConfig extends Config { - - public String mode; - public String bot; - - public void parseXML(Element element) { - super.parseXML(element); - - this.mode = element.getAttribute("mode"); - this.bot = element.getAttribute("bot"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + + public String mode; + public String bot; + + public void parseXML(Element element) { + super.parseXML(element); + + this.mode = element.getAttribute("mode"); + this.bot = element.getAttribute("bot"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java index 00b27ad..6479e18 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java @@ -24,49 +24,49 @@ import java.io.StringWriter; * DTO for XML browse options. */ public class BrowseConfig extends Config { - public String typeFilter; - public String category; - public String tag; - public String filter; - public String userFilter; - public String sort; - public String restrict; - public String page; - public String contentRating; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String typeFilter; + public String category; + public String tag; + public String filter; + public String userFilter; + public String sort; + public String restrict; + public String page; + public String contentRating; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java index becc5bc..3714328 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java @@ -26,52 +26,52 @@ import org.w3c.dom.Element; * DTO for XML channel config. */ public class ChannelConfig extends WebMediumConfig { - public String videoAccessMode; - public String audioAccessMode; - public String messages; - public String usersOnline; - public String adminsOnline; + public String videoAccessMode; + public String audioAccessMode; + public String messages; + public String usersOnline; + public String adminsOnline; - @Override - public String getType() { - return "channel"; - } + @Override + public String getType() { + return "channel"; + } - @Override - public String stats() { - return this.usersOnline + " users online, " + this.adminsOnline + " admins"; - } - - public WebMediumConfig credentials() { - ChannelConfig config = new ChannelConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.type = element.getAttribute("type"); - this.videoAccessMode = element.getAttribute("videoAccessMode"); - this.audioAccessMode = element.getAttribute("audioAccessMode"); - this.messages = element.getAttribute("messages"); - this.usersOnline = element.getAttribute("usersOnline"); - this.adminsOnline = element.getAttribute("adminsOnline"); - } + @Override + public String stats() { + return this.usersOnline + " users online, " + this.adminsOnline + " admins"; + } + + public WebMediumConfig credentials() { + ChannelConfig config = new ChannelConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.type = element.getAttribute("type"); + this.videoAccessMode = element.getAttribute("videoAccessMode"); + this.audioAccessMode = element.getAttribute("audioAccessMode"); + this.messages = element.getAttribute("messages"); + this.usersOnline = element.getAttribute("usersOnline"); + this.adminsOnline = element.getAttribute("adminsOnline"); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java index c2ce860..fec4518 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java @@ -27,73 +27,73 @@ import java.io.StringWriter; /** * DTO for XML chat config. */ -public class ChatConfig extends Config { - public String conversation; - public boolean correction; - public boolean offensive; - public boolean disconnect; - public String emote; - public String action; - public String message; - public boolean speak; - public boolean includeQuestion; - public boolean avatarHD; - public String avatarFormat; - public String avatar; - public String language; - public String voice; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } +public class ChatConfig extends Config { + public String conversation; + public boolean correction; + public boolean offensive; + public boolean disconnect; + public String emote; + public String action; + public String message; + public boolean speak; + public boolean includeQuestion; + public boolean avatarHD; + public String avatarFormat; + public String avatar; + public String language; + public String voice; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.message != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.message)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java index 9e93cab..d47f7e6 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java @@ -26,81 +26,81 @@ import org.w3c.dom.Node; /** * DTO for XML chat config. */ -public class ChatResponse extends Config { - public String conversation; - public String message; - public String question; - public String emote; - public String action; - public String pose; - public String command; - public String avatar; - public String avatar2; - public String avatar3; - public String avatar4; - public String avatar5; - public String avatarType; - public String avatarTalk; - public String avatarTalkType; - public String avatarAction; - public String avatarActionType; - public String avatarActionAudio; - public String avatarActionAudioType; - public String avatarAudio; - public String avatarAudioType; - public String avatarBackground; - public String speech; - - public boolean isVideo() { - return this.avatarType != null && this.avatarType.indexOf("video") != -1; - } - - public boolean isVideoTalk() { - return this.avatarTalkType != null && this.avatarTalkType.indexOf("video") != -1; - } +public class ChatResponse extends Config { + public String conversation; + public String message; + public String question; + public String emote; + public String action; + public String pose; + public String command; + public String avatar; + public String avatar2; + public String avatar3; + public String avatar4; + public String avatar5; + public String avatarType; + public String avatarTalk; + public String avatarTalkType; + public String avatarAction; + public String avatarActionType; + public String avatarActionAudio; + public String avatarActionAudioType; + public String avatarAudio; + public String avatarAudioType; + public String avatarBackground; + public String speech; - public void parseXML(Element element) { - this.conversation = element.getAttribute("conversation"); - this.emote = element.getAttribute("emote"); - this.action = element.getAttribute("action"); - this.pose = element.getAttribute("pose"); - this.avatar = element.getAttribute("avatar"); - this.avatar2 = element.getAttribute("avatar2"); - this.avatar3 = element.getAttribute("avatar3"); - this.avatar4 = element.getAttribute("avatar4"); - this.avatar5 = element.getAttribute("avatar5"); - this.avatarType = element.getAttribute("avatarType"); - this.avatarTalk = element.getAttribute("avatarTalk"); - this.avatarTalkType = element.getAttribute("avatarTalkType"); - this.avatarAction = element.getAttribute("avatarAction"); - this.avatarActionType = element.getAttribute("avatarActionType"); - this.avatarActionAudio = element.getAttribute("avatarActionAudio"); - this.avatarActionAudioType = element.getAttribute("avatarActionAudioType"); - this.avatarAudio = element.getAttribute("avatarAudio"); - this.avatarAudioType = element.getAttribute("avatarAudioType"); - this.avatarBackground = element.getAttribute("avatarBackground"); - this.speech = element.getAttribute("speech"); - this.command = element.getAttribute("command"); + public boolean isVideo() { + return this.avatarType != null && this.avatarType.indexOf("video") != -1; + } - Node node = element.getElementsByTagName("message").item(0); - if (node != null) { - this.message = node.getTextContent(); - } - node = element.getElementsByTagName("question").item(0); - if (node != null) { - this.question = node.getTextContent(); - } - } - - public ZSONObject getCommand(){ - if (this.command == null || this.command.equals("")){ - return null; - } - try { - return new ZSONObject(); - } catch (ZSONException exception) { - exception.printStackTrace(); - } - return null; - } + public boolean isVideoTalk() { + return this.avatarTalkType != null && this.avatarTalkType.indexOf("video") != -1; + } + + public void parseXML(Element element) { + this.conversation = element.getAttribute("conversation"); + this.emote = element.getAttribute("emote"); + this.action = element.getAttribute("action"); + this.pose = element.getAttribute("pose"); + this.avatar = element.getAttribute("avatar"); + this.avatar2 = element.getAttribute("avatar2"); + this.avatar3 = element.getAttribute("avatar3"); + this.avatar4 = element.getAttribute("avatar4"); + this.avatar5 = element.getAttribute("avatar5"); + this.avatarType = element.getAttribute("avatarType"); + this.avatarTalk = element.getAttribute("avatarTalk"); + this.avatarTalkType = element.getAttribute("avatarTalkType"); + this.avatarAction = element.getAttribute("avatarAction"); + this.avatarActionType = element.getAttribute("avatarActionType"); + this.avatarActionAudio = element.getAttribute("avatarActionAudio"); + this.avatarActionAudioType = element.getAttribute("avatarActionAudioType"); + this.avatarAudio = element.getAttribute("avatarAudio"); + this.avatarAudioType = element.getAttribute("avatarAudioType"); + this.avatarBackground = element.getAttribute("avatarBackground"); + this.speech = element.getAttribute("speech"); + this.command = element.getAttribute("command"); + + Node node = element.getElementsByTagName("message").item(0); + if (node != null) { + this.message = node.getTextContent(); + } + node = element.getElementsByTagName("question").item(0); + if (node != null) { + this.question = node.getTextContent(); + } + } + + public ZSONObject getCommand() { + if (this.command == null || this.command.equals("")) { + return null; + } + try { + return new ZSONObject(); + } catch (ZSONException exception) { + exception.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/Config.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/Config.java index dac4c7b..331cee4 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/Config.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/Config.java @@ -27,63 +27,63 @@ import org.w3c.dom.Element; * DTO for XML config. */ public class Config implements Cloneable { - public String application; - public String domain; - public String user; - public String token; - public String instance; - public String type; - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException exception) { - throw new Error(exception); - } - } - - public void addCredentials(SDKConnection connection) { - this.application = connection.getCredentials().getApplicationId(); - if (this.user == null && connection.getUser() != null) { - this.user = connection.getUser().user; - this.token = connection.getUser().token; - } - if (this.domain == null && connection.getDomain() != null) { - this.domain = connection.getDomain().id; - } - } - - public String toXML() { - return ""; - } - - public void parseXML(Element element) { - this.application = element.getAttribute("application"); - this.domain = element.getAttribute("domain"); - this.user = element.getAttribute("user"); - this.token = element.getAttribute("token"); - this.instance = element.getAttribute("instance"); - this.type = element.getAttribute("type"); - } - - public void writeCredentials(StringWriter writer) { - if (this.user != null && this.user.length() > 0) { - writer.write(" user=\"" + this.user + "\""); - } - if (this.token != null && this.token.length() > 0) { - writer.write(" token=\"" + this.token + "\""); - } - if (this.type != null && !this.type.equals("")) { - writer.write(" type=\"" + this.type + "\""); - } - if (this.instance != null && !this.instance.equals("")) { - writer.write(" instance=\"" + this.instance + "\""); - } - if (this.application != null && !this.application.equals("")) { - writer.write(" application=\"" + this.application + "\""); - } - if (this.domain != null && !this.domain.equals("")) { - writer.write(" domain=\"" + this.domain + "\""); - } - } + public String application; + public String domain; + public String user; + public String token; + public String instance; + public String type; + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException exception) { + throw new Error(exception); + } + } + + public void addCredentials(SDKConnection connection) { + this.application = connection.getCredentials().getApplicationId(); + if (this.user == null && connection.getUser() != null) { + this.user = connection.getUser().user; + this.token = connection.getUser().token; + } + if (this.domain == null && connection.getDomain() != null) { + this.domain = connection.getDomain().id; + } + } + + public String toXML() { + return ""; + } + + public void parseXML(Element element) { + this.application = element.getAttribute("application"); + this.domain = element.getAttribute("domain"); + this.user = element.getAttribute("user"); + this.token = element.getAttribute("token"); + this.instance = element.getAttribute("instance"); + this.type = element.getAttribute("type"); + } + + public void writeCredentials(StringWriter writer) { + if (this.user != null && this.user.length() > 0) { + writer.write(" user=\"" + this.user + "\""); + } + if (this.token != null && this.token.length() > 0) { + writer.write(" token=\"" + this.token + "\""); + } + if (this.type != null && !this.type.equals("")) { + writer.write(" type=\"" + this.type + "\""); + } + if (this.instance != null && !this.instance.equals("")) { + writer.write(" instance=\"" + this.instance + "\""); + } + if (this.application != null && !this.application.equals("")) { + writer.write(" application=\"" + this.application + "\""); + } + if (this.domain != null && !this.domain.equals("")) { + writer.write(" domain=\"" + this.domain + "\""); + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java index c9379f8..d8310d1 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java @@ -29,33 +29,33 @@ import org.w3c.dom.Node; */ public class ContentConfig extends Config { - public String name; - public String icon; - public String description; - - public void parseXML(Element element) { - super.parseXML(element); - - this.type = element.getAttribute("type"); - this.name = element.getAttribute("name"); - this.icon = element.getAttribute("icon"); - - Node node = element.getElementsByTagName("description").item(0); - if (node != null) { - this.description = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String name; + public String icon; + public String description; + + public void parseXML(Element element) { + super.parseXML(element); + + this.type = element.getAttribute("type"); + this.name = element.getAttribute("name"); + this.icon = element.getAttribute("icon"); + + Node node = element.getElementsByTagName("description").item(0); + if (node != null) { + this.description = node.getTextContent(); + } + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java index b90cf07..07175e8 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java @@ -32,26 +32,26 @@ import org.w3c.dom.NodeList; * DTO for XML conversation config. */ public class ConversationConfig extends Config { - public String id; - public String creationDate; - - public List input; - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.type = element.getAttribute("type"); - - NodeList nodes = element.getElementsByTagName("input"); - if (nodes != null && nodes.getLength() > 0) { - this.input = new ArrayList(); - for (int index = 0; index < nodes.getLength(); index++) { - Element node = (Element)nodes.item(index); - InputConfig config = new InputConfig(); - config.parseXML(node); - this.input.add(config); - } - } - } + public String id; + public String creationDate; + + public List input; + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.creationDate = element.getAttribute("creationDate"); + this.type = element.getAttribute("type"); + + NodeList nodes = element.getElementsByTagName("input"); + if (nodes != null && nodes.getLength() > 0) { + this.input = new ArrayList(); + for (int index = 0; index < nodes.getLength(); index++) { + Element node = (Element) nodes.item(index); + InputConfig config = new InputConfig(); + config.parseXML(node); + this.input.add(config); + } + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java index 6eee6ee..46d4cb6 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java @@ -26,31 +26,31 @@ import org.w3c.dom.Element; * DTO for XML domain config. */ public class DomainConfig extends WebMediumConfig { - public String creationMode; - - public String getType() { - return "domain"; - } - - public WebMediumConfig credentials() { - DomainConfig config = new DomainConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.creationMode = element.getAttribute("creationMode"); - } + public String creationMode; + + public String getType() { + return "domain"; + } + + public WebMediumConfig credentials() { + DomainConfig config = new DomainConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.creationMode = element.getAttribute("creationMode"); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java index 679f144..aab18b4 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java @@ -26,43 +26,43 @@ import org.w3c.dom.Element; * DTO for XML forum config. */ public class ForumConfig extends WebMediumConfig { - public String replyAccessMode; - public String postAccessMode; - public String posts; - - public String getType() { - return "forum"; - } + public String replyAccessMode; + public String postAccessMode; + public String posts; - @Override - public String stats() { - return this.posts + " posts"; - } - - public WebMediumConfig credentials() { - ForumConfig config = new ForumConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.replyAccessMode = element.getAttribute("replyAccessMode"); - this.postAccessMode = element.getAttribute("postAccessMode"); - this.posts = element.getAttribute("posts"); - } + public String getType() { + return "forum"; + } + + @Override + public String stats() { + return this.posts + " posts"; + } + + public WebMediumConfig credentials() { + ForumConfig config = new ForumConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.replyAccessMode = element.getAttribute("replyAccessMode"); + this.postAccessMode = element.getAttribute("postAccessMode"); + this.posts = element.getAttribute("posts"); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java index 4578bfc..c09c426 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java @@ -30,159 +30,160 @@ import org.w3c.dom.NodeList; /** * DTO for XML forum post config. */ -public class ForumPostConfig extends Config { - public String id; - public String topic; - public String summary; - public String details; - public String detailsText; - public String forum; - public String tags; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public boolean isAdmin; - public boolean isFlagged; - public String flaggedReason; - public boolean isFeatured; - public String creator; - public String creationDate; - public String views; - public String dailyViews; - public String weeklyViews; - public String monthlyViews; - public String replyCount; - public String parent; - public String avatar; - public List replies; - - public boolean equals(Object object) { - if (object instanceof ForumPostConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((ForumPostConfig)object).id); - } - return false; - } +public class ForumPostConfig extends Config { + public String id; + public String topic; + public String summary; + public String details; + public String detailsText; + public String forum; + public String tags; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public boolean isAdmin; + public boolean isFlagged; + public String flaggedReason; + public boolean isFeatured; + public String creator; + public String creationDate; + public String views; + public String dailyViews; + public String weeklyViews; + public String monthlyViews; + public String replyCount; + public String parent; + public String avatar; + public List replies; - @Override - public int hashCode() { - return Objects.hash(id, topic, summary, details, detailsText, forum, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isFeatured, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, replyCount, parent, avatar, replies); - } + public boolean equals(Object object) { + if (object instanceof ForumPostConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((ForumPostConfig) object).id); + } + return false; + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + @Override + public int hashCode() { + return Objects.hash(id, topic, summary, details, detailsText, forum, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isFeatured, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, replyCount, parent, avatar, replies); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.topic != null) { - writer.write(""); - writer.write(""); - } - if (this.details != null) { - String text = this.details; - writer.write("
"); - writer.write("
"); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.parent = element.getAttribute("parent"); - this.forum = element.getAttribute("forum"); - this.views = element.getAttribute("views"); - this.dailyViews = element.getAttribute("dailyViews"); - this.weeklyViews = element.getAttribute("weeklyViews"); - this.monthlyViews = element.getAttribute("monthlyViews"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.replyCount = element.getAttribute("replyCount"); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("summary").item(0); - if (node != null) { - this.summary = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("detailsText").item(0); - if (node != null) { - this.detailsText = node.getTextContent(); - } - node = element.getElementsByTagName("topic").item(0); - if (node != null) { - this.topic = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - NodeList nodes = element.getElementsByTagName("replies"); - if (nodes != null && nodes.getLength() > 0) { - this.replies = new ArrayList(); - for (int index = 0; index < nodes.getLength(); index++) { - Element reply = (Element)nodes.item(index); - ForumPostConfig config = new ForumPostConfig(); - config.parseXML(reply); - this.replies.add(config); - } - } - } - public ForumPostConfig credentials() { - ForumPostConfig config = new ForumPostConfig(); - config.id = this.id; - return config; - } + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } + + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.topic != null) { + writer.write(""); + writer.write(""); + } + if (this.details != null) { + String text = this.details; + writer.write("
"); + writer.write("
"); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.parent = element.getAttribute("parent"); + this.forum = element.getAttribute("forum"); + this.views = element.getAttribute("views"); + this.dailyViews = element.getAttribute("dailyViews"); + this.weeklyViews = element.getAttribute("weeklyViews"); + this.monthlyViews = element.getAttribute("monthlyViews"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.replyCount = element.getAttribute("replyCount"); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("summary").item(0); + if (node != null) { + this.summary = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("detailsText").item(0); + if (node != null) { + this.detailsText = node.getTextContent(); + } + node = element.getElementsByTagName("topic").item(0); + if (node != null) { + this.topic = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + NodeList nodes = element.getElementsByTagName("replies"); + if (nodes != null && nodes.getLength() > 0) { + this.replies = new ArrayList(); + for (int index = 0; index < nodes.getLength(); index++) { + Element reply = (Element) nodes.item(index); + ForumPostConfig config = new ForumPostConfig(); + config.parseXML(reply); + this.replies.add(config); + } + } + } + + public ForumPostConfig credentials() { + ForumPostConfig config = new ForumPostConfig(); + config.id = this.id; + return config; + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java index 6fedbf0..1d5d9b7 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java @@ -7,59 +7,61 @@ import org.w3c.dom.Element; /** * DTO for XML graphic config. */ -public class GraphicConfig extends WebMediumConfig{ - public String media; - public String fileName; - public String fileType; - - - @Override - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } +public class GraphicConfig extends WebMediumConfig { + public String media; + public String fileName; + public String fileType; - @Override - public String getType() { - return "graphic"; - } - @Override - public WebMediumConfig credentials() { - GraphicConfig config = new GraphicConfig(); - config.id = this.id; - return config; - } - public void parseXML(Element element) { - super.parseXML(element); - this.media = element.getAttribute("media"); - this.fileName = element.getAttribute("fileName"); - this.fileType = element.getAttribute("fileType"); + @Override + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + @Override + public String getType() { + return "graphic"; + } + + @Override + public WebMediumConfig credentials() { + GraphicConfig config = new GraphicConfig(); + config.id = this.id; + return config; + } + + public void parseXML(Element element) { + super.parseXML(element); + this.media = element.getAttribute("media"); + this.fileName = element.getAttribute("fileName"); + this.fileType = element.getAttribute("fileType"); // Node node = element.getElementsByTagName("media").item(0); // if (node != null) { // this.media = node.getTextContent(); // } - } - public boolean isVideo() { - return this.fileType != null && this.fileType.indexOf("video") != -1; - - } - - public boolean isAudio() { - return this.fileType != null && this.fileType.indexOf("audio") != -1; - } + } + + public boolean isVideo() { + return this.fileType != null && this.fileType.indexOf("video") != -1; + + } + + public boolean isAudio() { + return this.fileType != null && this.fileType.indexOf("audio") != -1; + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java index 9c99d0f..329707a 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java @@ -31,31 +31,31 @@ import java.util.Locale; * DTO for XML input config. */ public class InputConfig extends Config { - public String id; - public String creationDate; - public String speaker; - public String target; - public String value; - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.speaker = element.getAttribute("speaker"); - this.target = element.getAttribute("target"); - - Node node = element.getElementsByTagName("value").item(0); - if (node != null) { - this.value = node.getTextContent(); - } - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTime(date); - } catch (Exception exception) { - return creationDate; - } - } + public String id; + public String creationDate; + public String speaker; + public String target; + public String value; + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.creationDate = element.getAttribute("creationDate"); + this.speaker = element.getAttribute("speaker"); + this.target = element.getAttribute("target"); + + Node node = element.getElementsByTagName("value").item(0); + if (node != null) { + this.value = node.getTextContent(); + } + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayTime(date); + } catch (Exception exception) { + return creationDate; + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java index 59e8f80..7820784 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java @@ -27,69 +27,69 @@ import org.w3c.dom.Node; * DTO for XML bot instance config. */ public class InstanceConfig extends WebMediumConfig { - public String size; - public String instanceAvatar; - public boolean allowForking; - public boolean hasAPI; - public String template; - public int rank; - public int wins; - public int losses; - - public String getType() { - return "instance"; - } + public String size; + public String instanceAvatar; + public boolean allowForking; + public boolean hasAPI; + public String template; + public int rank; + public int wins; + public int losses; - @Override - public String stats() { - return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month"; - } + public String getType() { + return "instance"; + } - @Override - public InstanceConfig credentials() { - InstanceConfig config = new InstanceConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - writer.write(this.template); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.allowForking = Boolean.valueOf(element.getAttribute("allowForking")); - this.hasAPI = Boolean.valueOf(element.getAttribute("hasAPI")); - this.size = element.getAttribute("size"); - this.instanceAvatar = element.getAttribute("instanceAvatar"); - if (element.getAttribute("rank") != null && element.getAttribute("rank").trim().length() > 0) { - this.rank = Integer.valueOf(element.getAttribute("rank")); - } - if (element.getAttribute("wins") != null && element.getAttribute("wins").trim().length() > 0) { - this.wins = Integer.valueOf(element.getAttribute("wins")); - } - if (element.getAttribute("losses") != null && element.getAttribute("losses").trim().length() > 0) { - this.losses = Integer.valueOf(element.getAttribute("losses")); - } - - Node node = element.getElementsByTagName("template").item(0); - if (node != null) { - this.template = node.getTextContent(); - } - } + @Override + public String stats() { + return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month"; + } + + @Override + public InstanceConfig credentials() { + InstanceConfig config = new InstanceConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + writer.write(this.template); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.allowForking = Boolean.valueOf(element.getAttribute("allowForking")); + this.hasAPI = Boolean.valueOf(element.getAttribute("hasAPI")); + this.size = element.getAttribute("size"); + this.instanceAvatar = element.getAttribute("instanceAvatar"); + if (element.getAttribute("rank") != null && element.getAttribute("rank").trim().length() > 0) { + this.rank = Integer.valueOf(element.getAttribute("rank")); + } + if (element.getAttribute("wins") != null && element.getAttribute("wins").trim().length() > 0) { + this.wins = Integer.valueOf(element.getAttribute("wins")); + } + if (element.getAttribute("losses") != null && element.getAttribute("losses").trim().length() > 0) { + this.losses = Integer.valueOf(element.getAttribute("losses")); + } + + Node node = element.getElementsByTagName("template").item(0); + if (node != null) { + this.template = node.getTextContent(); + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java index 014f21d..33fd536 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java @@ -34,158 +34,159 @@ import java.util.Objects; * DTO for XML issue config. */ public class IssueConfig extends Config { - public String id; - public String title; - public String priority; - public String summary; - public String details; - public String detailsText; - public String tracker; - public String tags; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public boolean isAdmin; - public boolean isFlagged; - public String flaggedReason; - public boolean isPriority; - public String creator; - public String creationDate; - public String views; - public String dailyViews; - public String weeklyViews; - public String monthlyViews; - public String avatar; - - public boolean equals(Object object) { - if (object instanceof IssueConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((IssueConfig)object).id); - } - return false; - } + public String id; + public String title; + public String priority; + public String summary; + public String details; + public String detailsText; + public String tracker; + public String tags; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public boolean isAdmin; + public boolean isFlagged; + public String flaggedReason; + public boolean isPriority; + public String creator; + public String creationDate; + public String views; + public String dailyViews; + public String weeklyViews; + public String monthlyViews; + public String avatar; - @Override - public int hashCode() { - return Objects.hash(id, title, priority, summary, details, detailsText, tracker, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isPriority, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, avatar); - } + public boolean equals(Object object) { + if (object instanceof IssueConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((IssueConfig) object).id); + } + return false; + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + @Override + public int hashCode() { + return Objects.hash(id, title, priority, summary, details, detailsText, tracker, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isPriority, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, avatar); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.title != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.title)); - writer.write(""); - } - if (this.details != null) { - String text = this.details; - writer.write("
"); - writer.write(Utils.escapeHTML(text)); - writer.write("
"); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.tracker = element.getAttribute("tracker"); - this.priority = element.getAttribute("priority"); - this.views = element.getAttribute("views"); - this.dailyViews = element.getAttribute("dailyViews"); - this.weeklyViews = element.getAttribute("weeklyViews"); - this.monthlyViews = element.getAttribute("monthlyViews"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isPriority = Boolean.valueOf(element.getAttribute("isPriority")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("summary").item(0); - if (node != null) { - this.summary = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("detailsText").item(0); - if (node != null) { - this.detailsText = node.getTextContent(); - } - node = element.getElementsByTagName("title").item(0); - if (node != null) { - this.title = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - } - public IssueConfig credentials() { - IssueConfig config = new IssueConfig(); - config.id = this.id; - return config; - } + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.title != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.title)); + writer.write(""); + } + if (this.details != null) { + String text = this.details; + writer.write("
"); + writer.write(Utils.escapeHTML(text)); + writer.write("
"); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.tracker = element.getAttribute("tracker"); + this.priority = element.getAttribute("priority"); + this.views = element.getAttribute("views"); + this.dailyViews = element.getAttribute("dailyViews"); + this.weeklyViews = element.getAttribute("weeklyViews"); + this.monthlyViews = element.getAttribute("monthlyViews"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isPriority = Boolean.valueOf(element.getAttribute("isPriority")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("summary").item(0); + if (node != null) { + this.summary = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("detailsText").item(0); + if (node != null) { + this.detailsText = node.getTextContent(); + } + node = element.getElementsByTagName("title").item(0); + if (node != null) { + this.title = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + } + + public IssueConfig credentials() { + IssueConfig config = new IssueConfig(); + config.id = this.id; + return config; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayTimestamp(date); + } catch (Exception exception) { + return creationDate; + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java index 451d66c..19d0959 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java @@ -26,38 +26,38 @@ import java.io.StringWriter; * DTO for XML issue tracker config. */ public class IssueTrackerConfig extends WebMediumConfig { - public String createAccessMode; - public String issues; - - public String getType() { - return "issuetracker"; - } - - @Override - public String stats() { - return this.issues + " issues"; - } - - public WebMediumConfig credentials() { - IssueTrackerConfig config = new IssueTrackerConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.createAccessMode = element.getAttribute("createAccessMode"); - this.issues = element.getAttribute("issues"); - } + public String createAccessMode; + public String issues; + + public String getType() { + return "issuetracker"; + } + + @Override + public String stats() { + return this.issues + " issues"; + } + + public WebMediumConfig credentials() { + IssueTrackerConfig config = new IssueTrackerConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.createAccessMode = element.getAttribute("createAccessMode"); + this.issues = element.getAttribute("issues"); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java index 772b30a..cc4c7b1 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java @@ -27,96 +27,98 @@ import org.w3c.dom.Element; * DTO for XML voice config. */ public class LearningConfig extends Config { - - public String learningMode; - public String learningRate; - public String correctionMode; - public boolean enableComprehension; - public boolean enableEmoting; - public boolean enableEmotions; - public boolean enableConsciousness; - public boolean enableWiktionary; - public boolean enableResponseMatch; - public boolean learnGrammar; - public boolean synthesizeResponse; - public boolean fixFormulaCase; - public boolean checkExactMatchFirst; - public int scriptTimeout; - public int responseMatchTimeout; - public String conversationMatchPercentage; - public String discussionMatchPercentage; - - public void parseXML(Element element) { - super.parseXML(element); - - this.learningMode = element.getAttribute("learningMode"); - this.learningRate = element.getAttribute("learningRate"); - this.correctionMode = element.getAttribute("correctionMode"); - this.enableComprehension = Boolean.valueOf(element.getAttribute("enableComprehension")); - this.enableEmoting = Boolean.valueOf(element.getAttribute("enableEmoting")); - this.enableEmotions = Boolean.valueOf(element.getAttribute("enableEmotions")); - this.enableConsciousness = Boolean.valueOf(element.getAttribute("enableConsciousness")); - this.enableWiktionary = Boolean.valueOf(element.getAttribute("enableWiktionary")); - this.enableResponseMatch = Boolean.valueOf(element.getAttribute("enableResponseMatch")); - this.learnGrammar = Boolean.valueOf(element.getAttribute("learnGrammar")); - this.synthesizeResponse = Boolean.valueOf(element.getAttribute("synthesizeResponse")); - this.fixFormulaCase = Boolean.valueOf(element.getAttribute("fixFormulaCase")); - this.checkExactMatchFirst = Boolean.valueOf(element.getAttribute("checkExactMatchFirst")); - String value = element.getAttribute("scriptTimeout"); - if (value != null && value.length() > 0) { - try { - this.scriptTimeout = Integer.valueOf(value); - } catch (Exception ignore) {} - } - value = element.getAttribute("responseMatchTimeout"); - if (value != null && value.length() > 0) { - try { - this.responseMatchTimeout = Integer.valueOf(value); - } catch (Exception ignore) {} - } - this.conversationMatchPercentage = element.getAttribute("conversationMatchPercentage"); - this.discussionMatchPercentage = element.getAttribute("discussionMatchPercentage"); - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(" 0) { - writer.write(" conversationMatchPercentage=\"" + this.conversationMatchPercentage + "\""); - } - if (this.discussionMatchPercentage != null && this.discussionMatchPercentage.length() > 0) { - writer.write(" discussionMatchPercentage=\"" + this.discussionMatchPercentage + "\""); - } - if (this.learningRate != null && this.learningRate.length() > 0) { - writer.write(" learningRate=\"" + this.learningRate + "\""); - } - - writer.write("/>"); - return writer.toString(); - } + public void parseXML(Element element) { + super.parseXML(element); + + this.learningMode = element.getAttribute("learningMode"); + this.learningRate = element.getAttribute("learningRate"); + this.correctionMode = element.getAttribute("correctionMode"); + this.enableComprehension = Boolean.valueOf(element.getAttribute("enableComprehension")); + this.enableEmoting = Boolean.valueOf(element.getAttribute("enableEmoting")); + this.enableEmotions = Boolean.valueOf(element.getAttribute("enableEmotions")); + this.enableConsciousness = Boolean.valueOf(element.getAttribute("enableConsciousness")); + this.enableWiktionary = Boolean.valueOf(element.getAttribute("enableWiktionary")); + this.enableResponseMatch = Boolean.valueOf(element.getAttribute("enableResponseMatch")); + this.learnGrammar = Boolean.valueOf(element.getAttribute("learnGrammar")); + this.synthesizeResponse = Boolean.valueOf(element.getAttribute("synthesizeResponse")); + this.fixFormulaCase = Boolean.valueOf(element.getAttribute("fixFormulaCase")); + this.checkExactMatchFirst = Boolean.valueOf(element.getAttribute("checkExactMatchFirst")); + String value = element.getAttribute("scriptTimeout"); + if (value != null && value.length() > 0) { + try { + this.scriptTimeout = Integer.valueOf(value); + } catch (Exception ignore) { + } + } + value = element.getAttribute("responseMatchTimeout"); + if (value != null && value.length() > 0) { + try { + this.responseMatchTimeout = Integer.valueOf(value); + } catch (Exception ignore) { + } + } + this.conversationMatchPercentage = element.getAttribute("conversationMatchPercentage"); + this.discussionMatchPercentage = element.getAttribute("discussionMatchPercentage"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(" 0) { + writer.write(" conversationMatchPercentage=\"" + this.conversationMatchPercentage + "\""); + } + if (this.discussionMatchPercentage != null && this.discussionMatchPercentage.length() > 0) { + writer.write(" discussionMatchPercentage=\"" + this.discussionMatchPercentage + "\""); + } + if (this.learningRate != null && this.learningRate.length() > 0) { + writer.write(" learningRate=\"" + this.learningRate + "\""); + } + + writer.write("/>"); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java index d6bc189..ccb6059 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java @@ -27,44 +27,44 @@ import org.w3c.dom.Element; * DTO for XML media config. */ public class MediaConfig extends Config { - public long id; - public String name; - public String file; - public String key; - - public void parseXML(Element element) { - super.parseXML(element); - - this.id = Long.valueOf(element.getAttribute("id")); - this.name = element.getAttribute("name"); - this.type = element.getAttribute("type"); - this.file = element.getAttribute("file"); - this.key = element.getAttribute("key"); - } + public long id; + public String name; + public String file; + public String key; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + this.id = Long.valueOf(element.getAttribute("id")); + this.name = element.getAttribute("name"); + this.type = element.getAttribute("type"); + this.file = element.getAttribute("file"); + this.key = element.getAttribute("key"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java index 8984f85..0449961 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java @@ -15,87 +15,88 @@ * limitations under the License. * ******************************************************************************/ - + package org.botlibre.sdk.config; public class OfflineTemplateConfig { - private int imageId; - private int id_; - private String id; - private String title; - private String dec; - - public OfflineTemplateConfig(){ + private int imageId; + private int id_; + private String id; + private String title; + private String dec; + + public OfflineTemplateConfig() { + + } + + public OfflineTemplateConfig(int imageId, String title, String dec, String id) { + this.setImageId(imageId); + this.setTitle(title); + this.setDec(dec); + this.setId(id); + } + + public OfflineTemplateConfig(int imageId, String title, String dec, String id, int id_) { + this.setImageId(imageId); + this.setTitle(title); + this.setDec(dec); + this.setId(id); + this.setId_(id_); + } + + public int getImageId() { + return imageId; + } - } - - public OfflineTemplateConfig(int imageId, String title, String dec, String id){ - this.setImageId(imageId); - this.setTitle(title); - this.setDec(dec); - this.setId(id); - } - public OfflineTemplateConfig(int imageId, String title, String dec, String id,int id_){ - this.setImageId(imageId); - this.setTitle(title); - this.setDec(dec); - this.setId(id); - this.setId_(id_); - } - public int getImageId() { - return imageId; - } + public void setImageId(int imageId) { + this.imageId = imageId; + } - public void setImageId(int imageId) { - this.imageId = imageId; - } + public String getTitle() { + return title; + } - public String getTitle() { - return title; - } + public void setTitle(String title) { + this.title = title; + } + @Override + public String toString() { + return title + "\n" + dec; - public void setTitle(String title) { - this.title = title; - } - - @Override - public String toString(){ - return title + "\n" + dec; - - } + } - public String getDec() { - return dec; - } + public String getDec() { + return dec; + } - public void setDec(String dec) { - this.dec = dec; - } + public void setDec(String dec) { + this.dec = dec; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public int getId_() { - return id_; - } + public int getId_() { + return id_; + } - public void setId_(int id_) { - this.id_ = id_; - } + public void setId_(int id_) { + this.id_ = id_; + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java index bf74806..36022bc 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java @@ -31,175 +31,175 @@ import org.w3c.dom.Node; /** * DTO for XML response config. */ -public class ResponseConfig extends Config { - public String questionId; - public String responseId; - public String question; - public String response; - public String previous; - public String onRepeat; - public String label; - public String topic; - public String keywords; - public String required; - public String emotions; - public String actions; - public String poses; - public boolean noRepeat; - public boolean requirePrevious; - public boolean requireTopic; - public boolean flagged; - public String correctness; - public String command; +public class ResponseConfig extends Config { + public String questionId; + public String responseId; + public String question; + public String response; + public String previous; + public String onRepeat; + public String label; + public String topic; + public String keywords; + public String required; + public String emotions; + public String actions; + public String poses; + public boolean noRepeat; + public boolean requirePrevious; + public boolean requireTopic; + public boolean flagged; + public String correctness; + public String command; - public ResponseConfig() { - - } - - public boolean equals(Object object) { - if (this == object) { - return true; - } - if ((object instanceof ResponseConfig) && (this.responseId != null) && !this.responseId.isEmpty() - && this.responseId.equals(((ResponseConfig)object).responseId)) { - if (((this.questionId == null) || this.questionId.isEmpty()) - && (((ResponseConfig)object).questionId == null) || ((ResponseConfig)object).questionId.isEmpty()) { - return true; - } - if ((this.questionId != null) && !this.questionId.isEmpty() - && this.questionId.equals(((ResponseConfig)object).questionId)) { - return true; - } - } - return super.equals(object); - } + public ResponseConfig() { - @Override - public int hashCode() { - return Objects.hash(questionId, responseId, question, response, previous, onRepeat, label, topic, keywords, required, emotions, actions, poses, noRepeat, requirePrevious, requireTopic, flagged, correctness, command); - } + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + public boolean equals(Object object) { + if (this == object) { + return true; + } + if ((object instanceof ResponseConfig) && (this.responseId != null) && !this.responseId.isEmpty() + && this.responseId.equals(((ResponseConfig) object).responseId)) { + if (((this.questionId == null) || this.questionId.isEmpty()) + && (((ResponseConfig) object).questionId == null) || ((ResponseConfig) object).questionId.isEmpty()) { + return true; + } + if ((this.questionId != null) && !this.questionId.isEmpty() + && this.questionId.equals(((ResponseConfig) object).questionId)) { + return true; + } + } + return super.equals(object); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.question != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.question)); - writer.write(""); - } - if (this.response != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.response)); - writer.write(""); - } - if (this.previous != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.previous)); - writer.write(""); - } - if (this.onRepeat != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.onRepeat)); - writer.write(""); - } - if (this.command != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.command)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.questionId = element.getAttribute("questionId"); - this.responseId = element.getAttribute("responseId"); - this.label = element.getAttribute("label"); - this.topic = element.getAttribute("topic"); - this.keywords = element.getAttribute("keywords"); - this.required = element.getAttribute("required"); - this.emotions = element.getAttribute("emotions"); - this.actions = element.getAttribute("actions"); - this.poses = element.getAttribute("poses"); - this.type = element.getAttribute("type"); - this.correctness = element.getAttribute("correctness"); - if (element.getAttribute("noRepeat") != null) { - this.noRepeat = Boolean.valueOf(element.getAttribute("noRepeat")); - } - if (element.getAttribute("flagged") != null) { - this.flagged = Boolean.valueOf(element.getAttribute("flagged")); - } - if (element.getAttribute("requireTopic") != null) { - this.requireTopic = Boolean.valueOf(element.getAttribute("requireTopic")); - } - if (element.getAttribute("requirePrevious") != null) { - this.requirePrevious = Boolean.valueOf(element.getAttribute("requirePrevious")); - } - - Node node = element.getElementsByTagName("question").item(0); - if (node != null) { - this.question = node.getTextContent(); - } - node = element.getElementsByTagName("response").item(0); - if (node != null) { - this.response = node.getTextContent(); - } - node = element.getElementsByTagName("command").item(0); - if (node != null) { - this.command = node.getTextContent(); - this.command = this.command.replace(""", "\""); - } - } - - public ZSONObject getCommand(){ - if (this.command == null || this.command.equals("")){ - return null; - } - try { - return new ZSONObject(); - } catch (ZSONException e) { - e.printStackTrace(); - } - return null; - } + @Override + public int hashCode() { + return Objects.hash(questionId, responseId, question, response, previous, onRepeat, label, topic, keywords, required, emotions, actions, poses, noRepeat, requirePrevious, requireTopic, flagged, correctness, command); + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } + + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.question != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.question)); + writer.write(""); + } + if (this.response != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.response)); + writer.write(""); + } + if (this.previous != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.previous)); + writer.write(""); + } + if (this.onRepeat != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.onRepeat)); + writer.write(""); + } + if (this.command != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.command)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.questionId = element.getAttribute("questionId"); + this.responseId = element.getAttribute("responseId"); + this.label = element.getAttribute("label"); + this.topic = element.getAttribute("topic"); + this.keywords = element.getAttribute("keywords"); + this.required = element.getAttribute("required"); + this.emotions = element.getAttribute("emotions"); + this.actions = element.getAttribute("actions"); + this.poses = element.getAttribute("poses"); + this.type = element.getAttribute("type"); + this.correctness = element.getAttribute("correctness"); + if (element.getAttribute("noRepeat") != null) { + this.noRepeat = Boolean.valueOf(element.getAttribute("noRepeat")); + } + if (element.getAttribute("flagged") != null) { + this.flagged = Boolean.valueOf(element.getAttribute("flagged")); + } + if (element.getAttribute("requireTopic") != null) { + this.requireTopic = Boolean.valueOf(element.getAttribute("requireTopic")); + } + if (element.getAttribute("requirePrevious") != null) { + this.requirePrevious = Boolean.valueOf(element.getAttribute("requirePrevious")); + } + + Node node = element.getElementsByTagName("question").item(0); + if (node != null) { + this.question = node.getTextContent(); + } + node = element.getElementsByTagName("response").item(0); + if (node != null) { + this.response = node.getTextContent(); + } + node = element.getElementsByTagName("command").item(0); + if (node != null) { + this.command = node.getTextContent(); + this.command = this.command.replace(""", "\""); + } + } + + public ZSONObject getCommand() { + if (this.command == null || this.command.equals("")) { + return null; + } + try { + return new ZSONObject(); + } catch (ZSONException e) { + e.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java index c8bddf6..64b83bf 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java @@ -24,34 +24,34 @@ import java.io.StringWriter; * DTO for XML response search options. */ public class ResponseSearchConfig extends Config { - public String responseType; - public String inputType; - public String filter; - public String duration; - public String restrict; - public String page; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String responseType; + public String inputType; + public String filter; + public String duration; + public String restrict; + public String page; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java index a536caf..d7b0c0c 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java @@ -21,45 +21,44 @@ import java.io.StringWriter; import org.w3c.dom.Element; public class ScriptConfig extends WebMediumConfig { - public String language; - public String version; + public String language; + public String version; - public String getType() { - return "script"; - } + public String getType() { + return "script"; + } - public WebMediumConfig credentials() { - ScriptConfig config = new ScriptConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - return writer.toString(); - } - - public void parseXML(Element element){ - super.parseXML(element); - this.language = element.getAttribute("language"); - this.version = element.getAttribute("version"); - } - - @Override - public String toString() { - return this.name; - } - + public WebMediumConfig credentials() { + ScriptConfig config = new ScriptConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.language = element.getAttribute("language"); + this.version = element.getAttribute("version"); + } + + @Override + public String toString() { + return this.name; + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java index b90dfe5..8ff3cdc 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java @@ -42,87 +42,86 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -public class ScriptSourceConfig extends Config{ - public String id; - public String creationDate; - public String updateDate; - public boolean version; - public String versionName; - public String creator; - public String source; - - public ScriptSourceConfig credentials() { - ScriptSourceConfig config = new ScriptSourceConfig(); - config.creator = this.creator; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.source != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.source)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element){ - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.updateDate = element.getAttribute("updateDate"); - this.version = Boolean.valueOf(element.getAttribute("version")); - this.versionName = element.getAttribute("versionName"); - this.creator = element.getAttribute("creator"); - - Node node = element.getElementsByTagName("source").item(0); - if (node != null) { - this.source = node.getTextContent(); - } - } - - public String getNextVersion() { - if (this.source == null) { - return "0.1"; - } - - String version = this.source; - int index = version.lastIndexOf('.'); - if (index != -1) { - String major = version.substring(0, index); - String minor = version.substring(index + 1, version.length()); - try { - int value = Integer.valueOf(minor); - version = major + "." + (value + 1); - } - catch (NumberFormatException ignore) { - } - } - return version; - } +public class ScriptSourceConfig extends Config { + public String id; + public String creationDate; + public String updateDate; + public boolean version; + public String versionName; + public String creator; + public String source; + + public ScriptSourceConfig credentials() { + ScriptSourceConfig config = new ScriptSourceConfig(); + config.creator = this.creator; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.source != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.source)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.creationDate = element.getAttribute("creationDate"); + this.updateDate = element.getAttribute("updateDate"); + this.version = Boolean.valueOf(element.getAttribute("version")); + this.versionName = element.getAttribute("versionName"); + this.creator = element.getAttribute("creator"); + + Node node = element.getElementsByTagName("source").item(0); + if (node != null) { + this.source = node.getTextContent(); + } + } + + public String getNextVersion() { + if (this.source == null) { + return "0.1"; + } + + String version = this.source; + int index = version.lastIndexOf('.'); + if (index != -1) { + String major = version.substring(0, index); + String minor = version.substring(index + 1, version.length()); + try { + int value = Integer.valueOf(minor); + version = major + "." + (value + 1); + } catch (NumberFormatException ignore) { + } + } + return version; + } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/Speech.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/Speech.java index 63a6d47..9694370 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/Speech.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/Speech.java @@ -25,24 +25,24 @@ import java.io.StringWriter; * The object takes a message text, and a voice. */ public class Speech extends Config { - public String text; - public String voice; - public String mod; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String text; + public String voice; + public String mod; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java index 0bb5194..cd80f18 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java @@ -23,38 +23,37 @@ import org.botlibre.util.Utils; import java.io.StringWriter; - /** * DTO for XML training config. */ -public class TrainingConfig extends Config { - public String operation; - public String question; - public String response; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.question != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.question)); - writer.write(""); - } - if (this.response != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.response)); - writer.write(""); - } - - writer.write(""); - return writer.toString(); - } +public class TrainingConfig extends Config { + public String operation; + public String question; + public String response; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.question != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.question)); + writer.write(""); + } + if (this.response != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.response)); + writer.write(""); + } + + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java index b68c510..5961d5f 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java @@ -26,31 +26,31 @@ import org.w3c.dom.Element; /** * DTO for XML user admin config. */ -public class UserAdminConfig extends Config { - public String operation; - public String operationUser; - - public void parseXML(Element element) { - super.parseXML(element); - - this.operation = element.getAttribute("operation"); - this.operationUser = element.getAttribute("operationUser"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } +public class UserAdminConfig extends Config { + public String operation; + public String operationUser; + + public void parseXML(Element element) { + super.parseXML(element); + + this.operation = element.getAttribute("operation"); + this.operationUser = element.getAttribute("operationUser"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java index 21deb25..c258f20 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java @@ -29,130 +29,129 @@ import java.util.Objects; * DTO for XML user creation config. */ public class UserConfig extends Config { - public String password; - public String newPassword; - public String hint; - public String name; - public boolean showName; - public String email; - public String website; - public String bio; - public boolean over18; - public String avatar; - - public String connects; - public String bots; - public String posts; - public String messages; - public String forums; - public String scripts; - public String graphics; - public String avatars; - public String domains; - public String channels; - - public String joined; - public String lastConnect; - public boolean isFlagged; - public String flaggedReason; - + public String password; + public String newPassword; + public String hint; + public String name; + public boolean showName; + public String email; + public String website; + public String bio; + public boolean over18; + public String avatar; - - public void addCredentials(SDKConnection connection) { - this.application = connection.getCredentials().getApplicationId(); - if (connection.getDomain() != null) { - this.domain = connection.getDomain().id; - } - } - - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (!(object instanceof UserConfig)) { - return false; - } - return this.user != null && this.user.equals(((UserConfig)object).user); - } + public String connects; + public String bots; + public String posts; + public String messages; + public String forums; + public String scripts; + public String graphics; + public String avatars; + public String domains; + public String channels; - @Override - public int hashCode() { - return Objects.hash(password, newPassword, hint, name, showName, email, website, bio, over18, avatar, connects, bots, posts, messages, forums, scripts, graphics, avatars, domains, channels, joined, lastConnect, type, isFlagged, flaggedReason); - } + public String joined; + public String lastConnect; + public boolean isFlagged; + public String flaggedReason; + + + public void addCredentials(SDKConnection connection) { + this.application = connection.getCredentials().getApplicationId(); + if (connection.getDomain() != null) { + this.domain = connection.getDomain().id; + } + } + + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (!(object instanceof UserConfig)) { + return false; + } + return this.user != null && this.user.equals(((UserConfig) object).user); + } + + @Override + public int hashCode() { + return Objects.hash(password, newPassword, hint, name, showName, email, website, bio, over18, avatar, connects, bots, posts, messages, forums, scripts, graphics, avatars, domains, channels, joined, lastConnect, type, isFlagged, flaggedReason); + } + + public void parseXML(Element element) { + this.user = element.getAttribute("user"); + this.name = element.getAttribute("name"); + this.showName = Boolean.valueOf(element.getAttribute("showName")); + this.token = element.getAttribute("token"); + this.email = element.getAttribute("email"); + this.hint = element.getAttribute("hint"); + this.website = element.getAttribute("website"); + this.connects = element.getAttribute("connects"); + this.bots = element.getAttribute("bots"); + this.posts = element.getAttribute("posts"); + this.messages = element.getAttribute("messages"); + this.forums = element.getAttribute("forums"); + this.channels = element.getAttribute("channels"); + this.avatars = element.getAttribute("avatars"); + this.scripts = element.getAttribute("scripts"); + this.graphics = element.getAttribute("graphics"); + this.domains = element.getAttribute("domains"); + this.joined = element.getAttribute("joined"); + this.lastConnect = element.getAttribute("lastConnect"); + this.type = element.getAttribute("type"); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + + Node node = element.getElementsByTagName("bio").item(0); + if (node != null) { + this.bio = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.bio != null) { + writer.write(""); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } - public void parseXML(Element element) { - this.user = element.getAttribute("user"); - this.name = element.getAttribute("name"); - this.showName = Boolean.valueOf(element.getAttribute("showName")); - this.token = element.getAttribute("token"); - this.email = element.getAttribute("email"); - this.hint = element.getAttribute("hint"); - this.website = element.getAttribute("website"); - this.connects = element.getAttribute("connects"); - this.bots = element.getAttribute("bots"); - this.posts = element.getAttribute("posts"); - this.messages = element.getAttribute("messages"); - this.forums = element.getAttribute("forums"); - this.channels = element.getAttribute("channels"); - this.avatars = element.getAttribute("avatars"); - this.scripts = element.getAttribute("scripts"); - this.graphics = element.getAttribute("graphics"); - this.domains = element.getAttribute("domains"); - this.joined = element.getAttribute("joined"); - this.lastConnect = element.getAttribute("lastConnect"); - this.type = element.getAttribute("type"); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - - Node node = element.getElementsByTagName("bio").item(0); - if (node != null) { - this.bio = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.bio != null) { - writer.write(""); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java index 61e47a6..9ba0857 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java @@ -29,72 +29,72 @@ import org.w3c.dom.Node; * DTO for XML content config. */ public class UserMessageConfig extends Config { - public String id; - public String creationDate; - public String owner; - public String creator; - public String target; - public String parent; - public String subject; - public String message; - - public void parseXML(Element element) { - super.parseXML(element); - - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.owner = element.getAttribute("owner"); - this.creator = element.getAttribute("creator"); - this.target = element.getAttribute("target"); - this.parent = element.getAttribute("parent"); - - Node node = element.getElementsByTagName("subject").item(0); - if (node != null) { - this.subject = node.getTextContent(); - } - node = element.getElementsByTagName("message").item(0); - if (node != null) { - this.message = node.getTextContent(); - } - } + public String id; + public String creationDate; + public String owner; + public String creator; + public String target; + public String parent; + public String subject; + public String message; - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); + Node node = element.getElementsByTagName("subject").item(0); + if (node != null) { + this.subject = node.getTextContent(); + } + node = element.getElementsByTagName("message").item(0); + if (node != null) { + this.message = node.getTextContent(); + } + } - if (this.subject != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.subject)); - writer.write(""); - } - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.subject != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.subject)); + writer.write(""); + } + if (this.message != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.message)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java index 2c9a81f..78b63ce 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java @@ -28,50 +28,50 @@ import org.w3c.dom.Element; */ public class VoiceConfig extends Config { - public String voice; - public boolean nativeVoice; - public String language; - public String pitch; - public String speechRate; - public String mod; - - public void parseXML(Element element) { - super.parseXML(element); + public String voice; + public boolean nativeVoice; + public String language; + public String pitch; + public String speechRate; + public String mod; - this.voice = element.getAttribute("voice"); - this.nativeVoice = Boolean.valueOf(element.getAttribute("nativeVoice")); - this.language = element.getAttribute("language"); - this.pitch = element.getAttribute("pitch"); - this.speechRate = element.getAttribute("speechRate"); - this.mod = element.getAttribute("mod"); - } + public void parseXML(Element element) { + super.parseXML(element); - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java index 5fe3920..1807c1c 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java @@ -33,240 +33,240 @@ import org.w3c.dom.Node; */ public abstract class WebMediumConfig extends Config { - public String id; - public String name; - public boolean isAdmin; - public boolean isAdult; - public boolean isPrivate; - public boolean isHidden; - public String accessMode; - public boolean isFlagged; - public boolean isExternal; - public boolean isPaphus; - public boolean showAds = true; - public String forkAccessMode; - public String contentRating; - public String description; - public String details; - public String disclaimer; - public String website; - public String subdomain; - public String tags; - public String categories; - public String flaggedReason; - public String creator; - public String creationDate; - public String lastConnectedUser; - public String license; - public String avatar; - public String script; - public String graphic; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public String connects; - public String dailyConnects; - public String weeklyConnects; - public String monthlyConnects; - - public abstract String toXML(); - - public abstract String getType(); - - public abstract WebMediumConfig credentials(); - - public String stats() { - return ""; - } - - public boolean equals(Object object) { - if (object instanceof WebMediumConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((WebMediumConfig)object).id); - } - return false; - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayDate(date); - } catch (Exception exception) { - return creationDate; - } - } - - public long getToken() { - long token = 0; - if ((this.token != null) && (this.token.equals(""))) { - token = Long.valueOf(this.token); - } - return token; - } + public String id; + public String name; + public boolean isAdmin; + public boolean isAdult; + public boolean isPrivate; + public boolean isHidden; + public String accessMode; + public boolean isFlagged; + public boolean isExternal; + public boolean isPaphus; + public boolean showAds = true; + public String forkAccessMode; + public String contentRating; + public String description; + public String details; + public String disclaimer; + public String website; + public String subdomain; + public String tags; + public String categories; + public String flaggedReason; + public String creator; + public String creationDate; + public String lastConnectedUser; + public String license; + public String avatar; + public String script; + public String graphic; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public String connects; + public String dailyConnects; + public String weeklyConnects; + public String monthlyConnects; - public void writeXML(StringWriter writer) { - writeCredentials(writer); - if (this.id != null) { - writer.write(" id=\"" + this.id + "\""); - } - if (this.name != null) { - writer.write(" name=\"" + this.name + "\""); - } - if (this.isPrivate) { - writer.write(" isPrivate=\"true\""); - } - if (this.isHidden) { - writer.write(" isHidden=\"true\""); - } - if (this.accessMode != null && !this.accessMode.equals("")) { - writer.write(" accessMode=\"" + this.accessMode + "\""); - } - if (this.contentRating != null && !this.contentRating.equals("")) { - writer.write(" contentRating=\"" + this.contentRating + "\""); - } - if (this.forkAccessMode != null && !this.forkAccessMode.equals("")) { - writer.write(" forkAccessMode=\"" + this.forkAccessMode + "\""); - } + public abstract String toXML(); - if (this.stars != null && !this.stars.equals("")) { - writer.write(" stars=\"" + this.stars + "\""); - } - if (this.isAdult) { - writer.write(" isAdult=\"true\""); - } - if (this.isFlagged) { - writer.write(" isFlagged=\"true\""); - } - if (this.isExternal) { - writer.write(" isExternal=\"true\""); - } - if (this.showAds) { - writer.write(" showAds=\"true\""); - } - writer.write(">"); - if (this.description != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.description)); - writer.write(""); - } - if (this.details != null) { - writer.write("
"); - writer.write(Utils.escapeHTML(this.details)); - writer.write("
"); - } - if (this.disclaimer != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.disclaimer)); - writer.write(""); - } - if (this.categories != null) { - writer.write(""); - writer.write(this.categories); - writer.write(""); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.license != null) { - writer.write(""); - writer.write(this.license); - writer.write(""); - } - if (this.website != null) { - writer.write(""); - writer.write(this.website); - writer.write(""); - } - if (this.subdomain != null) { - writer.write(""); - writer.write(this.subdomain); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.name = element.getAttribute("name"); - this.creationDate = element.getAttribute("creationDate"); - this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate")); - this.isHidden = Boolean.valueOf(element.getAttribute("isHidden")); - this.accessMode = element.getAttribute("accessMode"); - this.contentRating = element.getAttribute("contentRating"); - this.forkAccessMode = element.getAttribute("forkAccessMode"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.isAdult = Boolean.valueOf(element.getAttribute("isAdult")); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isExternal = Boolean.valueOf(element.getAttribute("isExternal")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - this.connects = element.getAttribute("connects"); - this.dailyConnects = element.getAttribute("dailyConnects"); - this.weeklyConnects = element.getAttribute("weeklyConnects"); - this.showAds = Boolean.valueOf(element.getAttribute("showAds")); - this.monthlyConnects = element.getAttribute("monthlyConnects"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("description").item(0); - if (node != null) { - this.description = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("disclaimer").item(0); - if (node != null) { - this.disclaimer = node.getTextContent(); - } - node = element.getElementsByTagName("categories").item(0); - if (node != null) { - this.categories = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("lastConnectedUser").item(0); - if (node != null) { - this.lastConnectedUser = node.getTextContent(); - } - node = element.getElementsByTagName("license").item(0); - if (node != null) { - this.license = node.getTextContent(); - } - node = element.getElementsByTagName("website").item(0); - if (node != null) { - this.website = node.getTextContent(); - } - node = element.getElementsByTagName("subdomain").item(0); - if (node != null) { - this.subdomain = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - } + public abstract String getType(); + + public abstract WebMediumConfig credentials(); + + public String stats() { + return ""; + } + + public boolean equals(Object object) { + if (object instanceof WebMediumConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((WebMediumConfig) object).id); + } + return false; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayDate(date); + } catch (Exception exception) { + return creationDate; + } + } + + public long getToken() { + long token = 0; + if ((this.token != null) && (this.token.equals(""))) { + token = Long.valueOf(this.token); + } + return token; + } + + public void writeXML(StringWriter writer) { + writeCredentials(writer); + if (this.id != null) { + writer.write(" id=\"" + this.id + "\""); + } + if (this.name != null) { + writer.write(" name=\"" + this.name + "\""); + } + if (this.isPrivate) { + writer.write(" isPrivate=\"true\""); + } + if (this.isHidden) { + writer.write(" isHidden=\"true\""); + } + if (this.accessMode != null && !this.accessMode.equals("")) { + writer.write(" accessMode=\"" + this.accessMode + "\""); + } + if (this.contentRating != null && !this.contentRating.equals("")) { + writer.write(" contentRating=\"" + this.contentRating + "\""); + } + if (this.forkAccessMode != null && !this.forkAccessMode.equals("")) { + writer.write(" forkAccessMode=\"" + this.forkAccessMode + "\""); + } + + if (this.stars != null && !this.stars.equals("")) { + writer.write(" stars=\"" + this.stars + "\""); + } + if (this.isAdult) { + writer.write(" isAdult=\"true\""); + } + if (this.isFlagged) { + writer.write(" isFlagged=\"true\""); + } + if (this.isExternal) { + writer.write(" isExternal=\"true\""); + } + if (this.showAds) { + writer.write(" showAds=\"true\""); + } + writer.write(">"); + if (this.description != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.description)); + writer.write(""); + } + if (this.details != null) { + writer.write("
"); + writer.write(Utils.escapeHTML(this.details)); + writer.write("
"); + } + if (this.disclaimer != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.disclaimer)); + writer.write(""); + } + if (this.categories != null) { + writer.write(""); + writer.write(this.categories); + writer.write(""); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.license != null) { + writer.write(""); + writer.write(this.license); + writer.write(""); + } + if (this.website != null) { + writer.write(""); + writer.write(this.website); + writer.write(""); + } + if (this.subdomain != null) { + writer.write(""); + writer.write(this.subdomain); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.name = element.getAttribute("name"); + this.creationDate = element.getAttribute("creationDate"); + this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate")); + this.isHidden = Boolean.valueOf(element.getAttribute("isHidden")); + this.accessMode = element.getAttribute("accessMode"); + this.contentRating = element.getAttribute("contentRating"); + this.forkAccessMode = element.getAttribute("forkAccessMode"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.isAdult = Boolean.valueOf(element.getAttribute("isAdult")); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isExternal = Boolean.valueOf(element.getAttribute("isExternal")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + this.connects = element.getAttribute("connects"); + this.dailyConnects = element.getAttribute("dailyConnects"); + this.weeklyConnects = element.getAttribute("weeklyConnects"); + this.showAds = Boolean.valueOf(element.getAttribute("showAds")); + this.monthlyConnects = element.getAttribute("monthlyConnects"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("description").item(0); + if (node != null) { + this.description = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("disclaimer").item(0); + if (node != null) { + this.disclaimer = node.getTextContent(); + } + node = element.getElementsByTagName("categories").item(0); + if (node != null) { + this.categories = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("lastConnectedUser").item(0); + if (node != null) { + this.lastConnectedUser = node.getTextContent(); + } + node = element.getElementsByTagName("license").item(0); + if (node != null) { + this.license = node.getTextContent(); + } + node = element.getElementsByTagName("website").item(0); + if (node != null) { + this.website = node.getTextContent(); + } + node = element.getElementsByTagName("subdomain").item(0); + if (node != null) { + this.subdomain = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + } } \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/TextStream.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/TextStream.java index 9222816..f342afd 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/TextStream.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/TextStream.java @@ -29,630 +29,630 @@ import java.util.Set; */ public class TextStream { - public static final String WHITESPACE =" \t\n\r\f"; - public static final String HTTP =" \t\n\r\f\""; - public static final String TOKENS =" \t\n\r\f.,:;!()?[]{}+=^&*\"`~|/\\<>"; - public static final String TERMINATORS =".?!。"; - private static Set ABBREVIATIONS = new HashSet(Arrays.asList(new String[]{"mr","ms", "mrs", "dr", "inc", "sr", "jr", "st"})); - public static Set IGNORABLE = new HashSet(Arrays.asList(new String[]{"'","`", "\"", ","})); - - /** - * The text being streamed. - */ - protected String text; - - /** - * The current stream index into the text. - */ - protected int index; - - public TextStream(String text) { - this.index = 0; - this.text = text; - } - - public void reset() { - this.index = 0; - } - - public char last() { - if (this.index <= 1) { - return (char)0; - } - return this.text.charAt(this.index - 2); - } - - public char current() { - if (this.index <= 0) { - return (char)0; - } - return this.text.charAt(this.index - 1); - } - - public char peekPrevious() { - if (this.index <= 1) { - return (char)0; - } - return this.text.charAt(this.index - 2); - } - - public char peek() { - if (atEnd()) { - return (char)-1; - } - return this.text.charAt(this.index); - } - - public int peekCodePoint() { - if (atEnd()) { - return (int)-1; - } - return this.text.codePointAt(this.index); - } - - public char next() { - if (this.index >= this.text.length()) { - return (char)-1; - } - char next = this.text.charAt(this.index); - this.index++; - return next; - } - - public char previous() { - this.index--; - char previous = current(); - return previous; - } - - public void skip() { - if (this.index >= this.text.length()) { - return; - } - this.index++; - } - - public void skip(int count) { - this.index = Math.min(this.index + count, this.text.length()); - } - - public void backup(int count) { - this.index = Math.max(this.index - count, 0); - } - - public void backup() { - this.index--; - } - - public String peek(int count) { - int start = this.index; - int end = Math.min(this.index + count, this.text.length()); - return this.text.substring(start, end); - } - - public String previous(int count) { - int end = this.index - 2; - if (end <= 0) { - return ""; - } - int start = Math.max(end - count, 0); - return this.text.substring(start, end); - } - - public String next(int count) { - int start = this.index; - this.index = Math.min(this.index + count, this.text.length()); - return this.text.substring(start, this.index); - } - - public boolean atEnd() { - return this.index >= this.text.length(); - } - - public boolean atStart() { - return this.index == 0; - } - - public String upTo(char token) { - return upTo(token, false); - } - - public void skipTo(char token) { - skipTo(token, false); - } - - public String upToEnd() { - int start = this.index; - this.index = this.text.length(); - return this.text.substring(start, this.index); - } - - public String upTo(char token, boolean including) { - return upTo(token, including, false); - } - - public String upTo(char token, boolean including, boolean resetIfNotFound) { - int start = this.index; - boolean found = skipTo(token, including); - if (resetIfNotFound && !found) { - this.index = start; - return ""; - } - return this.text.substring(start, this.index); - } - - public boolean skipTo(char token, boolean including) { - boolean found = false; - while (!atEnd()) { - if (peek() == token) { - found = true; - break; - } - skip(); - } - if (found && including) { - skip(); - } - return found; - } - - public void backupTo(char token) { - backupTo(token, false); - } - - public void backupTo(char token, boolean including) { - boolean found = false; - while (this.index > 0) { - if (current() == token) { - found = true; - break; - } - backup(); - } - if (found && including) { - backup(); - } - } - - public String upToAny(String tokens) { - return upToAny(tokens, false); - } - - public String upToAny(String tokens, boolean including) { - int start = this.index; - skipToAny(tokens, including); - return this.text.substring(start, this.index); - } - - public void skipToAny(String tokens) { - skipToAny(tokens, false); - } - - public void skipToAny(String tokens, boolean including) { - boolean found = false; - while (!atEnd()) { - if (tokens.indexOf(peek()) != -1) { - found = true; - break; - } - skip(); - } - if (found && including) { - skip(); - } - } - - public String upToAll(String tokens) { - return upToAll(tokens, false); - } - - public String upToAll(String tokens, boolean including) { - return upToAll(tokens, including, false); - } - - public String upToAll(String tokens, boolean including, boolean resetIfNotFound) { - int start = this.index; - boolean found = skipToAll(tokens, including); - if (resetIfNotFound && !found) { - this.index = start; - return ""; - } - return this.text.substring(start, this.index); - } - - public void skipToAll(String tokens) { - skipToAll(tokens, false); - } - - public boolean skipToAll(String tokens, boolean including) { - int tokenIndex = 0; - boolean found = false; - while (!atEnd()) { - if (peek() == tokens.charAt(tokenIndex)) { - tokenIndex++; - if (tokenIndex == tokens.length()) { - found = true; - break; - } - } else { - tokenIndex = 0; - } - skip(); - } - if (found) { - if (including) { - skip(); - } else { - this.index = index - (tokens.length() - 1); - } - } - return found; - } - - public void backupToAll(String tokens) { - backupToAll(tokens, false); - } - - public void backupToAll(String tokens, boolean including) { - int tokenIndex = 1; - int length = tokens.length(); - boolean found = false; - while (this.index > 0) { - if (current() == tokens.charAt(length - tokenIndex)) { - if (tokenIndex == tokens.length()) { - found = true; - break; - } - tokenIndex++; - } else { - tokenIndex = 1; - } - backup(); - } - if (found) { - if (including) { - backup(); - } else { - this.index = index + (length - 1); - } - } - } - - public void backupToAny(String tokens) { - backupToAny(tokens, false); - } - - public void backupToAny(String tokens, boolean including) { - boolean found = false; - while (!atStart()) { - if (tokens.indexOf(peekPrevious()) != -1) { - found = true; - break; - } - backup(); - } - if (found && including) { - backup(); - } - } - - public String peekWord() { - int position = this.index; - String word = nextWord(); - this.index = position; - return word; - } - - public List allWords() { - List words = new ArrayList(); - while (!atEnd()) { - String word = nextWord(); - if (word != null) { - words.add(word); - } - } - return words; - } - - public List csv() { - List words = new ArrayList(); - skipWhitespace(); - while (!atEnd()) { - String word = upTo(','); - if (!atEnd()) { - skip(); - skipWhitespace(); - } - if ((word != null) && !word.trim().equals("")) { - words.add(word); - } - } - return words; - } - - public String peekPreviousWord() { - int original = this.index; - backupWhitespace(); - int start = this.index; - if (atStart()) { - return null; - } - char current = current(); - if ((TOKENS.indexOf(current) != -1) || (isWordSymbol(current))) { - previous(); - String word = String.valueOf(current); - this.index = original; - return word; - } - backupToAny(TOKENS); - String word = this.text.substring(Math.max(this.index - 1, 0), start); - this.index = original; - return word; - } - - public boolean isWordSymbol(char character) { - Character.UnicodeBlock block = Character.UnicodeBlock.of(character); - return ((block == Character.UnicodeBlock.HIRAGANA) - || (block == Character.UnicodeBlock.KATAKANA) - || (block == Character.UnicodeBlock.HANGUL_SYLLABLES) - || (block == Character.UnicodeBlock.HANGUL_JAMO)) - && !Character.isDigit(character); - } - - public String nextQuotes() { - if (atEnd()) { - return ""; - } - int start = this.index; - skipQuotes(); - int end = this.index - 1; - if (atEnd() && current() != '"') { - end = this.index; - } - String quotes = this.text.substring(start, end); - return quotes; - } - - public String nextQuotesExcludeDoubleQuote() { - String quotes = nextQuotes(); - if (quotes.contains("\"\"")) { - quotes = quotes.replace("\"\"", "\""); - } - return quotes; - } - - public void skipQuotes() { - if (atEnd()) { - return; - } - char next = next(); - char peek = peek(); - while (!atEnd() && ((next != '"') || (peek == '"'))) { - if ((next == '"') && (peek == '"')) { - skip(); - } - if (next == '{') { - skipBrackets(); - } - next = next(); - peek = peek(); - } - } - - public void skipBrackets() { - if (atEnd()) { - return; - } - char next = next(); - while (!atEnd() && (next != '}')) { - if (next == '"') { - skipQuotes(); - } - next = next(); - } - } - - public String nextWord() { - skipWhitespace(); - if (atEnd()) { - return null; - } - //int peek = peekCodePoint(); - char peek = peek(); - boolean isSign = (peek == '-') || (peek == '+'); - // Check for "1-1" vs "1 - -1" - if (isSign && !atStart()) { - backup(); - char previous = peek(); - if (Character.isLetterOrDigit(previous)) { - skip(); - skip(); - return String.valueOf(peek); - } - skip(); - } - if (isWordSymbol(peek) || (!Character.isLetterOrDigit(peek) && peek != '_' && peek != '@' && !isSign)) { - skip(); - Character.UnicodeBlock block = Character.UnicodeBlock.of(peek); - if (block == Character.UnicodeBlock.HIGH_SURROGATES) { - skip(); - return this.text.substring(this.index - 2, this.index); - } - return String.valueOf(peek); - } - // Check url. - if (peek == 'h') { - if (peek(7).equals("http://") || peek(8).equals("https://")) { - return upToAny(HTTP); - } - } - int start = this.index; - boolean wasDigit = Character.isDigit(peek); - skip(); - while (!atEnd()) { - //peek = peekCodePoint(); - peek = peek(); - boolean isDigit = Character.isDigit(peek); - if (isWordSymbol(peek)) { - break; - } - // "-1" is ok - if (isSign && !isDigit) { - break; - } else { - // Allow "1.1", "1,000", "ab-ba", "ab_ba" - if (!Character.isLetter(peek) && !isDigit && (peek != '_')) { - if (wasDigit) { - if ((peek != '.') && (peek != ',') && (peek != '@')) { - break; - } - } else { - if ((peek != '-') && (peek != '_') && (peek != '@') && (peek != '.')) { - break; - } - } - } - } - wasDigit = isDigit; - skip(); - // Could have been "1.", "1.a" - if ((((peek == '.') && !Character.isLetter(peek())) || (peek == ',')) && !Character.isDigit(peek())) { - backup(); - break; - } - isSign = false; - } - return this.text.substring(start, this.index); - } - - public void skipWord() { - skipWhitespace(); - if (atEnd()) { - return; - } - if (TOKENS.indexOf(peek()) != -1) { - skip(); - } - // Check url. - if (peek() == 'h') { - if (peek(7).equals("http://")) { - skipToAny(WHITESPACE); - } - } - skipToAny(TOKENS); - } - - public String nextSentence() { - skipWhitespace(); - if (atEnd()) { - return null; - } - int start = this.index; - skipToAny(TERMINATORS, true); - while (!atEnd()) { - char peek = peek(); - boolean done = WHITESPACE.indexOf(peek) != -1; - if (done) { - if (current() != '.') { - break; - } - backup(); - String word = peekPreviousWord(); - skip(); - if (ABBREVIATIONS.contains(word.toLowerCase()) - || ((word.length() == 1) && (Character.isUpperCase(word.charAt(0))))) { - done = false; - } else { - break; - } - } else if (isWordSymbol(peek)) { - break; - } - skipToAny(TERMINATORS, true); - } - return this.text.substring(start, this.index); - } - - public String nextWhitespace() { - int start = this.index; - while (!atEnd() && (WHITESPACE.indexOf(peek()) != -1)) { - skip(); - } - return this.text.substring(start, this.index); - } - - public boolean skipWhitespace() { - boolean found = false; - while (!atEnd() && (Character.isWhitespace(peek()))) { - skip(); - found = true; - } - return found; - } - - public void backupWhitespace() { - while (!atStart() && (WHITESPACE.indexOf(current()) != -1)) { - backup(); - } - } - - public String nextLine() { - return upToAll("\n", true); - } - - public String currentLine() { - int position = this.index; - backupToAll("\n"); - String line = nextLine(); - this.index = position; - return line; - } - - public int currentLineNumber() { - int position = this.index; - this.index = 0; - int count = 0; - int last = this.index; - while (this.index < position) { - skipLine(); - if (this.index < position) { - count++; - } - if (this.index == last) { - break; - } - last = this.index; - } - this.index = position; - return count + 1; - } - - public int currentLineColumn() { - int position = this.index; - backupToAll("\n"); - int column = position - this.index; - this.index = position; - return column + 1; - } - - public void skipLine() { - skipToAll("\n", true); - } - - public int getPosition() { - return index; - } - - public void setPosition(int index) { - this.index = index; - } - - public String getText() { - return text; - } - - public String toString() { - return peek(text.length()); - } - + public static final String WHITESPACE = " \t\n\r\f"; + public static final String HTTP = " \t\n\r\f\""; + public static final String TOKENS = " \t\n\r\f.,:;!()?[]{}+=^&*\"`~|/\\<>"; + public static final String TERMINATORS = ".?!。"; + private static Set ABBREVIATIONS = new HashSet(Arrays.asList(new String[]{"mr", "ms", "mrs", "dr", "inc", "sr", "jr", "st"})); + public static Set IGNORABLE = new HashSet(Arrays.asList(new String[]{"'", "`", "\"", ","})); + + /** + * The text being streamed. + */ + protected String text; + + /** + * The current stream index into the text. + */ + protected int index; + + public TextStream(String text) { + this.index = 0; + this.text = text; + } + + public void reset() { + this.index = 0; + } + + public char last() { + if (this.index <= 1) { + return (char) 0; + } + return this.text.charAt(this.index - 2); + } + + public char current() { + if (this.index <= 0) { + return (char) 0; + } + return this.text.charAt(this.index - 1); + } + + public char peekPrevious() { + if (this.index <= 1) { + return (char) 0; + } + return this.text.charAt(this.index - 2); + } + + public char peek() { + if (atEnd()) { + return (char) -1; + } + return this.text.charAt(this.index); + } + + public int peekCodePoint() { + if (atEnd()) { + return (int) -1; + } + return this.text.codePointAt(this.index); + } + + public char next() { + if (this.index >= this.text.length()) { + return (char) -1; + } + char next = this.text.charAt(this.index); + this.index++; + return next; + } + + public char previous() { + this.index--; + char previous = current(); + return previous; + } + + public void skip() { + if (this.index >= this.text.length()) { + return; + } + this.index++; + } + + public void skip(int count) { + this.index = Math.min(this.index + count, this.text.length()); + } + + public void backup(int count) { + this.index = Math.max(this.index - count, 0); + } + + public void backup() { + this.index--; + } + + public String peek(int count) { + int start = this.index; + int end = Math.min(this.index + count, this.text.length()); + return this.text.substring(start, end); + } + + public String previous(int count) { + int end = this.index - 2; + if (end <= 0) { + return ""; + } + int start = Math.max(end - count, 0); + return this.text.substring(start, end); + } + + public String next(int count) { + int start = this.index; + this.index = Math.min(this.index + count, this.text.length()); + return this.text.substring(start, this.index); + } + + public boolean atEnd() { + return this.index >= this.text.length(); + } + + public boolean atStart() { + return this.index == 0; + } + + public String upTo(char token) { + return upTo(token, false); + } + + public void skipTo(char token) { + skipTo(token, false); + } + + public String upToEnd() { + int start = this.index; + this.index = this.text.length(); + return this.text.substring(start, this.index); + } + + public String upTo(char token, boolean including) { + return upTo(token, including, false); + } + + public String upTo(char token, boolean including, boolean resetIfNotFound) { + int start = this.index; + boolean found = skipTo(token, including); + if (resetIfNotFound && !found) { + this.index = start; + return ""; + } + return this.text.substring(start, this.index); + } + + public boolean skipTo(char token, boolean including) { + boolean found = false; + while (!atEnd()) { + if (peek() == token) { + found = true; + break; + } + skip(); + } + if (found && including) { + skip(); + } + return found; + } + + public void backupTo(char token) { + backupTo(token, false); + } + + public void backupTo(char token, boolean including) { + boolean found = false; + while (this.index > 0) { + if (current() == token) { + found = true; + break; + } + backup(); + } + if (found && including) { + backup(); + } + } + + public String upToAny(String tokens) { + return upToAny(tokens, false); + } + + public String upToAny(String tokens, boolean including) { + int start = this.index; + skipToAny(tokens, including); + return this.text.substring(start, this.index); + } + + public void skipToAny(String tokens) { + skipToAny(tokens, false); + } + + public void skipToAny(String tokens, boolean including) { + boolean found = false; + while (!atEnd()) { + if (tokens.indexOf(peek()) != -1) { + found = true; + break; + } + skip(); + } + if (found && including) { + skip(); + } + } + + public String upToAll(String tokens) { + return upToAll(tokens, false); + } + + public String upToAll(String tokens, boolean including) { + return upToAll(tokens, including, false); + } + + public String upToAll(String tokens, boolean including, boolean resetIfNotFound) { + int start = this.index; + boolean found = skipToAll(tokens, including); + if (resetIfNotFound && !found) { + this.index = start; + return ""; + } + return this.text.substring(start, this.index); + } + + public void skipToAll(String tokens) { + skipToAll(tokens, false); + } + + public boolean skipToAll(String tokens, boolean including) { + int tokenIndex = 0; + boolean found = false; + while (!atEnd()) { + if (peek() == tokens.charAt(tokenIndex)) { + tokenIndex++; + if (tokenIndex == tokens.length()) { + found = true; + break; + } + } else { + tokenIndex = 0; + } + skip(); + } + if (found) { + if (including) { + skip(); + } else { + this.index = index - (tokens.length() - 1); + } + } + return found; + } + + public void backupToAll(String tokens) { + backupToAll(tokens, false); + } + + public void backupToAll(String tokens, boolean including) { + int tokenIndex = 1; + int length = tokens.length(); + boolean found = false; + while (this.index > 0) { + if (current() == tokens.charAt(length - tokenIndex)) { + if (tokenIndex == tokens.length()) { + found = true; + break; + } + tokenIndex++; + } else { + tokenIndex = 1; + } + backup(); + } + if (found) { + if (including) { + backup(); + } else { + this.index = index + (length - 1); + } + } + } + + public void backupToAny(String tokens) { + backupToAny(tokens, false); + } + + public void backupToAny(String tokens, boolean including) { + boolean found = false; + while (!atStart()) { + if (tokens.indexOf(peekPrevious()) != -1) { + found = true; + break; + } + backup(); + } + if (found && including) { + backup(); + } + } + + public String peekWord() { + int position = this.index; + String word = nextWord(); + this.index = position; + return word; + } + + public List allWords() { + List words = new ArrayList(); + while (!atEnd()) { + String word = nextWord(); + if (word != null) { + words.add(word); + } + } + return words; + } + + public List csv() { + List words = new ArrayList(); + skipWhitespace(); + while (!atEnd()) { + String word = upTo(','); + if (!atEnd()) { + skip(); + skipWhitespace(); + } + if ((word != null) && !word.trim().equals("")) { + words.add(word); + } + } + return words; + } + + public String peekPreviousWord() { + int original = this.index; + backupWhitespace(); + int start = this.index; + if (atStart()) { + return null; + } + char current = current(); + if ((TOKENS.indexOf(current) != -1) || (isWordSymbol(current))) { + previous(); + String word = String.valueOf(current); + this.index = original; + return word; + } + backupToAny(TOKENS); + String word = this.text.substring(Math.max(this.index - 1, 0), start); + this.index = original; + return word; + } + + public boolean isWordSymbol(char character) { + Character.UnicodeBlock block = Character.UnicodeBlock.of(character); + return ((block == Character.UnicodeBlock.HIRAGANA) + || (block == Character.UnicodeBlock.KATAKANA) + || (block == Character.UnicodeBlock.HANGUL_SYLLABLES) + || (block == Character.UnicodeBlock.HANGUL_JAMO)) + && !Character.isDigit(character); + } + + public String nextQuotes() { + if (atEnd()) { + return ""; + } + int start = this.index; + skipQuotes(); + int end = this.index - 1; + if (atEnd() && current() != '"') { + end = this.index; + } + String quotes = this.text.substring(start, end); + return quotes; + } + + public String nextQuotesExcludeDoubleQuote() { + String quotes = nextQuotes(); + if (quotes.contains("\"\"")) { + quotes = quotes.replace("\"\"", "\""); + } + return quotes; + } + + public void skipQuotes() { + if (atEnd()) { + return; + } + char next = next(); + char peek = peek(); + while (!atEnd() && ((next != '"') || (peek == '"'))) { + if ((next == '"') && (peek == '"')) { + skip(); + } + if (next == '{') { + skipBrackets(); + } + next = next(); + peek = peek(); + } + } + + public void skipBrackets() { + if (atEnd()) { + return; + } + char next = next(); + while (!atEnd() && (next != '}')) { + if (next == '"') { + skipQuotes(); + } + next = next(); + } + } + + public String nextWord() { + skipWhitespace(); + if (atEnd()) { + return null; + } + //int peek = peekCodePoint(); + char peek = peek(); + boolean isSign = (peek == '-') || (peek == '+'); + // Check for "1-1" vs "1 - -1" + if (isSign && !atStart()) { + backup(); + char previous = peek(); + if (Character.isLetterOrDigit(previous)) { + skip(); + skip(); + return String.valueOf(peek); + } + skip(); + } + if (isWordSymbol(peek) || (!Character.isLetterOrDigit(peek) && peek != '_' && peek != '@' && !isSign)) { + skip(); + Character.UnicodeBlock block = Character.UnicodeBlock.of(peek); + if (block == Character.UnicodeBlock.HIGH_SURROGATES) { + skip(); + return this.text.substring(this.index - 2, this.index); + } + return String.valueOf(peek); + } + // Check url. + if (peek == 'h') { + if (peek(7).equals("http://") || peek(8).equals("https://")) { + return upToAny(HTTP); + } + } + int start = this.index; + boolean wasDigit = Character.isDigit(peek); + skip(); + while (!atEnd()) { + //peek = peekCodePoint(); + peek = peek(); + boolean isDigit = Character.isDigit(peek); + if (isWordSymbol(peek)) { + break; + } + // "-1" is ok + if (isSign && !isDigit) { + break; + } else { + // Allow "1.1", "1,000", "ab-ba", "ab_ba" + if (!Character.isLetter(peek) && !isDigit && (peek != '_')) { + if (wasDigit) { + if ((peek != '.') && (peek != ',') && (peek != '@')) { + break; + } + } else { + if ((peek != '-') && (peek != '_') && (peek != '@') && (peek != '.')) { + break; + } + } + } + } + wasDigit = isDigit; + skip(); + // Could have been "1.", "1.a" + if ((((peek == '.') && !Character.isLetter(peek())) || (peek == ',')) && !Character.isDigit(peek())) { + backup(); + break; + } + isSign = false; + } + return this.text.substring(start, this.index); + } + + public void skipWord() { + skipWhitespace(); + if (atEnd()) { + return; + } + if (TOKENS.indexOf(peek()) != -1) { + skip(); + } + // Check url. + if (peek() == 'h') { + if (peek(7).equals("http://")) { + skipToAny(WHITESPACE); + } + } + skipToAny(TOKENS); + } + + public String nextSentence() { + skipWhitespace(); + if (atEnd()) { + return null; + } + int start = this.index; + skipToAny(TERMINATORS, true); + while (!atEnd()) { + char peek = peek(); + boolean done = WHITESPACE.indexOf(peek) != -1; + if (done) { + if (current() != '.') { + break; + } + backup(); + String word = peekPreviousWord(); + skip(); + if (ABBREVIATIONS.contains(word.toLowerCase()) + || ((word.length() == 1) && (Character.isUpperCase(word.charAt(0))))) { + done = false; + } else { + break; + } + } else if (isWordSymbol(peek)) { + break; + } + skipToAny(TERMINATORS, true); + } + return this.text.substring(start, this.index); + } + + public String nextWhitespace() { + int start = this.index; + while (!atEnd() && (WHITESPACE.indexOf(peek()) != -1)) { + skip(); + } + return this.text.substring(start, this.index); + } + + public boolean skipWhitespace() { + boolean found = false; + while (!atEnd() && (Character.isWhitespace(peek()))) { + skip(); + found = true; + } + return found; + } + + public void backupWhitespace() { + while (!atStart() && (WHITESPACE.indexOf(current()) != -1)) { + backup(); + } + } + + public String nextLine() { + return upToAll("\n", true); + } + + public String currentLine() { + int position = this.index; + backupToAll("\n"); + String line = nextLine(); + this.index = position; + return line; + } + + public int currentLineNumber() { + int position = this.index; + this.index = 0; + int count = 0; + int last = this.index; + while (this.index < position) { + skipLine(); + if (this.index < position) { + count++; + } + if (this.index == last) { + break; + } + last = this.index; + } + this.index = position; + return count + 1; + } + + public int currentLineColumn() { + int position = this.index; + backupToAll("\n"); + int column = position - this.index; + this.index = position; + return column + 1; + } + + public void skipLine() { + skipToAll("\n", true); + } + + public int getPosition() { + return index; + } + + public void setPosition(int index) { + this.index = index; + } + + public String getText() { + return text; + } + + public String toString() { + return peek(text.length()); + } + } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java index e601245..7290f41 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java @@ -22,19 +22,19 @@ package org.botlibre.sdk; */ public class SDKException extends RuntimeException { - public SDKException(Exception exception) { - super(exception.getMessage(), exception); - } - - public SDKException(String message) { - super(message); - } - - public SDKException(String message, Exception exception) { - super(message, exception); - } - - public static SDKException parseFailure(Exception exception) { - throw new SDKException("parse failure", exception); - } + public SDKException(Exception exception) { + super(exception.getMessage(), exception); + } + + public SDKException(String message) { + super(message); + } + + public SDKException(String message, Exception exception) { + super(message, exception); + } + + public static SDKException parseFailure(Exception exception) { + throw new SDKException("parse failure", exception); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index 29003b2..d06ae1a 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java @@ -28,46 +28,46 @@ import org.botlibre.sdk.config.UserConfig; */ public class LoginAbility extends LibreAbility implements Component.ClickedListener { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_login); + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_login); - Button connectButton = (Button)findComponentById(ResourceTable.Id_connectButton); - connectButton.setClickedListener(this); - Button signUpButton = (Button)findComponentById(ResourceTable.Id_signUpButton); - signUpButton.setClickedListener(this); - } - - /** - * Start a chat session with the selected instance and the user. - */ - public void connect() { - TextField text = (TextField) findComponentById(ResourceTable.Id_userText); + Button connectButton = (Button) findComponentById(ResourceTable.Id_connectButton); + connectButton.setClickedListener(this); + Button signUpButton = (Button) findComponentById(ResourceTable.Id_signUpButton); + signUpButton.setClickedListener(this); + } + + /** + * Start a chat session with the selected instance and the user. + */ + public void connect() { + TextField text = (TextField) findComponentById(ResourceTable.Id_userText); String user = text.getText().toString().trim(); text = (TextField) findComponentById(ResourceTable.Id_passwordText); String password = text.getText().toString().trim(); - - UserConfig config = new UserConfig(); - config.user = user; - config.password = password; + + UserConfig config = new UserConfig(); + config.user = user; + config.password = password; HttpConnectAction action = new HttpConnectAction(this, config, true); - action.execute(); + action.execute(); } - - public void signUp() { - terminateAbility(); - - startOpenAbility(this,CreateUserAbility.class.getName()); - } - @Override - public void onClick(Component component) { - if(component.getId() == ResourceTable.Id_connectButton){//登录 - connect(); - } - if(component.getId() == ResourceTable.Id_signUpButton){// 注册 - signUp(); - } - } + public void signUp() { + terminateAbility(); + + startOpenAbility(this, CreateUserAbility.class.getName()); + } + + @Override + public void onClick(Component component) { + if (component.getId() == ResourceTable.Id_connectButton) {//登录 + connect(); + } + if (component.getId() == ResourceTable.Id_signUpButton) {// 注册 + signUp(); + } + } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java index 5d84dc9..593b2e5 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java @@ -29,91 +29,92 @@ import java.util.Map; * DTO for XML avatar config. */ public class AvatarConfig extends WebMediumConfig { - public Map mediaConfig; - private String avatarFormat; - private boolean avatarHD; - public String background; - public String icon; - - public String getType() { - return "avatar"; - } - public AvatarConfig(){ - mediaConfig = new HashMap(); - } - - public ChatResponse chatReply(ChatResponse chat) { - String emotion = MicroConnection.getBot().mood().currentEmotionalState().name(); - String action = MicroConnection.getBot().avatar().getAction(); - String pose = MicroConnection.getBot().avatar().getPose(); - if (this.getBackground() != null) { - String background = this.getBackground(); - chat.avatarBackground = background; - } - List matching = null; - - // Audio - if (action != null) { - matching = this.getAudio(action, pose); - if (!matching.isEmpty()) { - AvatarMedia media = Utils.random(matching); - String [] array = media.media.split("\\."); - chat.avatarActionAudio = media.mediaId + "." + array[1]; - chat.avatarActionAudioType = media.getType(); - } - } - matching = this.getAudio("", pose); - if (!matching.isEmpty()) { - AvatarMedia media = Utils.random(matching); - String [] array = media.media.split("\\."); - chat.avatarAudio = media.mediaId + "." + array[1]; - chat.avatarAudioType = media.getType(); - } - // Image/video - if (action != null) { - matching = this.getMedia(emotion, action, pose, ""); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatarAction = media.mediaId+"."+array[1]; - } - } - matching = this.getMedia(emotion, "", pose, ""); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatar = media.mediaId+"."+array[1]; - chat.avatar2 = null; - chat.avatar3 = null; - chat.avatar4 = null; - chat.avatar5 = null; - if (matching.size() > 1) { - AvatarMedia media2 = randomMatch(matching); - AvatarMedia media3 = randomMatch(matching); - AvatarMedia media4 = randomMatch(matching); - AvatarMedia media5 = randomMatch(matching); - if (media != media2 || media != media3 || media != media4 || media != media5) { - array = media2.media.split("\\."); - chat.avatar2 = media2.mediaId+"."+array[1]; - array = media3.media.split("\\."); - chat.avatar3 = media3.mediaId+"."+array[1]; - array = media4.media.split("\\."); - chat.avatar4 = media4.mediaId+"."+array[1]; - array = media5.media.split("\\."); - chat.avatar5 = media5.mediaId+"."+array[1]; - } - } - chat.avatarType = media.getType(); - } - matching = this.getMedia(emotion, "", pose, "talking"); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String [] array = media.media.split("\\."); - chat.avatarTalk = media.mediaId +"." +array[1]; - chat.avatarTalkType = media.getType(); - } - return chat; - } + public Map mediaConfig; + private String avatarFormat; + private boolean avatarHD; + public String background; + public String icon; + + public String getType() { + return "avatar"; + } + + public AvatarConfig() { + mediaConfig = new HashMap(); + } + + public ChatResponse chatReply(ChatResponse chat) { + String emotion = MicroConnection.getBot().mood().currentEmotionalState().name(); + String action = MicroConnection.getBot().avatar().getAction(); + String pose = MicroConnection.getBot().avatar().getPose(); + if (this.getBackground() != null) { + String background = this.getBackground(); + chat.avatarBackground = background; + } + List matching = null; + + // Audio + if (action != null) { + matching = this.getAudio(action, pose); + if (!matching.isEmpty()) { + AvatarMedia media = Utils.random(matching); + String[] array = media.media.split("\\."); + chat.avatarActionAudio = media.mediaId + "." + array[1]; + chat.avatarActionAudioType = media.getType(); + } + } + matching = this.getAudio("", pose); + if (!matching.isEmpty()) { + AvatarMedia media = Utils.random(matching); + String[] array = media.media.split("\\."); + chat.avatarAudio = media.mediaId + "." + array[1]; + chat.avatarAudioType = media.getType(); + } + // Image/video + if (action != null) { + matching = this.getMedia(emotion, action, pose, ""); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatarAction = media.mediaId + "." + array[1]; + } + } + matching = this.getMedia(emotion, "", pose, ""); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatar = media.mediaId + "." + array[1]; + chat.avatar2 = null; + chat.avatar3 = null; + chat.avatar4 = null; + chat.avatar5 = null; + if (matching.size() > 1) { + AvatarMedia media2 = randomMatch(matching); + AvatarMedia media3 = randomMatch(matching); + AvatarMedia media4 = randomMatch(matching); + AvatarMedia media5 = randomMatch(matching); + if (media != media2 || media != media3 || media != media4 || media != media5) { + array = media2.media.split("\\."); + chat.avatar2 = media2.mediaId + "." + array[1]; + array = media3.media.split("\\."); + chat.avatar3 = media3.mediaId + "." + array[1]; + array = media4.media.split("\\."); + chat.avatar4 = media4.mediaId + "." + array[1]; + array = media5.media.split("\\."); + chat.avatar5 = media5.mediaId + "." + array[1]; + } + } + chat.avatarType = media.getType(); + } + matching = this.getMedia(emotion, "", pose, "talking"); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatarTalk = media.mediaId + "." + array[1]; + chat.avatarTalkType = media.getType(); + } + return chat; + } // public String getDefaultAvatarMediaOne(){ // String name = null; @@ -175,425 +176,425 @@ public class AvatarConfig extends WebMediumConfig { // public String getTypeAvatarMedia(){ // return type; // } - - public WebMediumConfig credentials() { - AvatarConfig config = new AvatarConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - - public void parseXML(Element element) { - super.parseXML(element); - } - /** - * debug - * - * @param emotion - * @param action - * @param pose - * @param pose2 - * @return list - */ - public List getMedia(String emotion, String action, String pose, String pose2) { - if (emotion == null || emotion.isEmpty()) { - emotion = "NONE"; - } else { - emotion = emotion.toUpperCase(); - } - if (action == null) { - action = ""; - } - if (pose == null) { - pose = ""; - } - if (pose2 == null) { - pose2 = ""; - } - boolean talking = pose2.equals("talking"); - List matches = new ArrayList(); - boolean none = emotion.equals("NONE"); - - boolean[][] matching = new boolean[this.mediaConfig.size()][4]; - int index = 0; - // All match. - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean emotionMatch = media.getEmotions().contains(emotion) || (none && media.getEmotions().isEmpty()); - if (emotionMatch && emotion.equals("RAGE") && media.getEmotions().contains("COURAGE")) { - // Both contain "rage". - emotionMatch = false; - } - if (emotionMatch && emotion.equals("LIKE") && media.getEmotions().contains("DISLIKE")) { - // Both contain "like". - emotionMatch = false; - } - boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); - boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); - boolean pose2Match = (!pose2.isEmpty() && media.getPoses().contains(pose2)) || pose2.isEmpty(); - if (!pose2Match && pose2.equals("talking")) { - pose2Match = media.getTalking(); - } else if (media.getTalking() && !talking) { - pose2Match = false; - } - matching[index][0] = emotionMatch; - matching[index][1] = actionMatch; - matching[index][2] = poseMatch; - matching[index][3] = pose2Match; - index++; - if (emotionMatch && actionMatch && poseMatch && pose2Match) { - matches.add(media); - } - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 and pose matches. - if (!pose2.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean poseMatch = matching[index][2]; - boolean pose2Match = matching[index][3]; - if (poseMatch && pose2Match) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 and emotion matches. - index = 0; - for (AvatarMedia media :this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - boolean pose2Match = matching[index][3]; - if (emotionMatch && pose2Match) { - if (!media.getPoses().isEmpty()) { - index++; - continue; - } - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean pose2Match = matching[index][3]; - if (pose2Match) { - if (!media.getPoses().isEmpty()) { - index++; - continue; - } - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 any matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean pose2Match = matching[index][3]; - if (pose2Match) { - matches.add(media); - } - index++; - } - // For pose2, the pose is required (i.e. talking). - return matches; - } - // Action and pose matches. - if (!action.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean actionMatch = matching[index][1]; - boolean poseMatch = matching[index][2]; - if (actionMatch && poseMatch) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Action matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean actionMatch = matching[index][1]; - if (actionMatch - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - // For actions, the action is required. - return matches; - } - // Pose and emotion matches. - if (!pose.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - boolean poseMatch = matching[index][2]; - if (poseMatch && emotionMatch && media.getActions().isEmpty()) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean poseMatch = matching[index][2]; - if (poseMatch && media.getActions().isEmpty() - && (media.getEmotions().isEmpty() || media.getEmotions().contains("NONE"))) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - } - // Emotion matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - if (emotionMatch - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Default matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - return matches; - } + public WebMediumConfig credentials() { + AvatarConfig config = new AvatarConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + + public void parseXML(Element element) { + super.parseXML(element); + } + + /** + * debug + * + * @param emotion + * @param action + * @param pose + * @param pose2 + * @return list + */ + public List getMedia(String emotion, String action, String pose, String pose2) { + if (emotion == null || emotion.isEmpty()) { + emotion = "NONE"; + } else { + emotion = emotion.toUpperCase(); + } + if (action == null) { + action = ""; + } + if (pose == null) { + pose = ""; + } + if (pose2 == null) { + pose2 = ""; + } + boolean talking = pose2.equals("talking"); + List matches = new ArrayList(); + boolean none = emotion.equals("NONE"); + + boolean[][] matching = new boolean[this.mediaConfig.size()][4]; + int index = 0; + // All match. + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean emotionMatch = media.getEmotions().contains(emotion) || (none && media.getEmotions().isEmpty()); + if (emotionMatch && emotion.equals("RAGE") && media.getEmotions().contains("COURAGE")) { + // Both contain "rage". + emotionMatch = false; + } + if (emotionMatch && emotion.equals("LIKE") && media.getEmotions().contains("DISLIKE")) { + // Both contain "like". + emotionMatch = false; + } + boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); + boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); + boolean pose2Match = (!pose2.isEmpty() && media.getPoses().contains(pose2)) || pose2.isEmpty(); + if (!pose2Match && pose2.equals("talking")) { + pose2Match = media.getTalking(); + } else if (media.getTalking() && !talking) { + pose2Match = false; + } + matching[index][0] = emotionMatch; + matching[index][1] = actionMatch; + matching[index][2] = poseMatch; + matching[index][3] = pose2Match; + index++; + if (emotionMatch && actionMatch && poseMatch && pose2Match) { + matches.add(media); + } + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 and pose matches. + if (!pose2.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean poseMatch = matching[index][2]; + boolean pose2Match = matching[index][3]; + if (poseMatch && pose2Match) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 and emotion matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + boolean pose2Match = matching[index][3]; + if (emotionMatch && pose2Match) { + if (!media.getPoses().isEmpty()) { + index++; + continue; + } + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean pose2Match = matching[index][3]; + if (pose2Match) { + if (!media.getPoses().isEmpty()) { + index++; + continue; + } + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 any matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean pose2Match = matching[index][3]; + if (pose2Match) { + matches.add(media); + } + index++; + } + // For pose2, the pose is required (i.e. talking). + return matches; + } + // Action and pose matches. + if (!action.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean actionMatch = matching[index][1]; + boolean poseMatch = matching[index][2]; + if (actionMatch && poseMatch) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Action matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean actionMatch = matching[index][1]; + if (actionMatch + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + // For actions, the action is required. + return matches; + } + // Pose and emotion matches. + if (!pose.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + boolean poseMatch = matching[index][2]; + if (poseMatch && emotionMatch && media.getActions().isEmpty()) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean poseMatch = matching[index][2]; + if (poseMatch && media.getActions().isEmpty() + && (media.getEmotions().isEmpty() || media.getEmotions().contains("NONE"))) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + } + // Emotion matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + if (emotionMatch + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Default matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + return matches; + } + + /** + * getAudio + * + * @param action + * @param pose + * @return list + */ + public List getAudio(String action, String pose) { + if (action == null) { + action = ""; + } + if (pose == null) { + pose = ""; + } + List matches = new ArrayList(); - /** - * getAudio - * - * @param action - * @param pose - * @return list - */ - public List getAudio(String action, String pose) { - if (action == null) { - action = ""; - } - if (pose == null) { - pose = ""; - } - List matches = new ArrayList(); - - boolean[][] matching = new boolean[this.mediaConfig.size()][2]; - int index = 0; - // All match. - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); - boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); - matching[index][0] = actionMatch; - matching[index][1] = poseMatch; - index++; - if (actionMatch && poseMatch) { - matches.add(media); - } - } - if (!matches.isEmpty()) { - return matches; - } - // Action matches. - if (!action.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean actionMatch = matching[index][0]; - if (actionMatch && media.getPoses().isEmpty()) { - matches.add(media); - } - index++; - } - // For actions, the action is required. - return matches; - } - // Pose matches. - if (!pose.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean poseMatch = matching[index][1]; - if (poseMatch && media.getActions().isEmpty()) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - } - // Default matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - return matches; - } + boolean[][] matching = new boolean[this.mediaConfig.size()][2]; + int index = 0; + // All match. + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); + boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); + matching[index][0] = actionMatch; + matching[index][1] = poseMatch; + index++; + if (actionMatch && poseMatch) { + matches.add(media); + } + } + if (!matches.isEmpty()) { + return matches; + } + // Action matches. + if (!action.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean actionMatch = matching[index][0]; + if (actionMatch && media.getPoses().isEmpty()) { + matches.add(media); + } + index++; + } + // For actions, the action is required. + return matches; + } + // Pose matches. + if (!pose.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean poseMatch = matching[index][1]; + if (poseMatch && media.getActions().isEmpty()) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + } + // Default matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + return matches; + } - public AvatarMedia randomMatch(List matches) { - List formatMatches = new ArrayList(); - String format = "mp4"; - if (this.avatarFormat != null && !this.avatarFormat.isEmpty()) { - format = this.avatarFormat; - } - for (AvatarMedia media : matches) { - if (media.getType().indexOf(format) != -1) { - formatMatches.add(media); - } - } - if (formatMatches.isEmpty()) { - List hdMatches = new ArrayList(); - for (AvatarMedia media : matches) { - if (this.avatarHD && media.getHD()) { - hdMatches.add(media); - } else if (!this.avatarHD && !media.getHD()) { - hdMatches.add(media); - } - } - if (!hdMatches.isEmpty()) { - return Utils.random(hdMatches); - } - return Utils.random(matches); - } else { - List hdMatches = new ArrayList(); - for (AvatarMedia media : formatMatches) { - if (this.avatarHD && media.getHD()) { - hdMatches.add(media); - } else if (!this.avatarHD && !media.getHD()) { - hdMatches.add(media); - } - } - if (!hdMatches.isEmpty()) { - return Utils.random(hdMatches); - } - return Utils.random(formatMatches); - } - } + public AvatarMedia randomMatch(List matches) { + List formatMatches = new ArrayList(); + String format = "mp4"; + if (this.avatarFormat != null && !this.avatarFormat.isEmpty()) { + format = this.avatarFormat; + } + for (AvatarMedia media : matches) { + if (media.getType().indexOf(format) != -1) { + formatMatches.add(media); + } + } + if (formatMatches.isEmpty()) { + List hdMatches = new ArrayList(); + for (AvatarMedia media : matches) { + if (this.avatarHD && media.getHD()) { + hdMatches.add(media); + } else if (!this.avatarHD && !media.getHD()) { + hdMatches.add(media); + } + } + if (!hdMatches.isEmpty()) { + return Utils.random(hdMatches); + } + return Utils.random(matches); + } else { + List hdMatches = new ArrayList(); + for (AvatarMedia media : formatMatches) { + if (this.avatarHD && media.getHD()) { + hdMatches.add(media); + } else if (!this.avatarHD && !media.getHD()) { + hdMatches.add(media); + } + } + if (!hdMatches.isEmpty()) { + return Utils.random(hdMatches); + } + return Utils.random(formatMatches); + } + } - public String getBackground(){ - return background; - } + public String getBackground() { + return background; + } - public String getIcon(){ - return icon; - } + public String getIcon() { + return icon; + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java index b63e9e5..abb935a 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java @@ -26,102 +26,107 @@ import java.io.StringWriter; * The media is the short URL to the media file on the server. */ public class AvatarMedia extends Config { - public String mediaId; - public String name; - public String type; - public String media; - public String emotions; - public String actions; - public String poses; - public boolean hd; - public boolean talking; - - public void parseXML(Element element) { - super.parseXML(element); - - this.mediaId = element.getAttribute("mediaId"); - this.name = element.getAttribute("name"); - this.type = element.getAttribute("type"); - this.media = element.getAttribute("media"); - this.emotions = element.getAttribute("emotions"); - this.actions = element.getAttribute("actions"); - this.poses = element.getAttribute("poses"); - this.hd = Boolean.valueOf(element.getAttribute("hd")); - this.talking = Boolean.valueOf(element.getAttribute("talking")); - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public boolean getHD() { - return hd; - } - public boolean isImage() { - return this.type.contains("image") || this.type.isEmpty(); - } - - public boolean isVideo() { - return this.type != null && this.type.indexOf("video") != -1; - } - - public boolean isAudio() { - return this.type != null && this.type.indexOf("audio") != -1; - } - public String getType() { - return type; - } - public String getEmotions() { - return emotions; - } - - public void setEmotions(String emotions) { - this.emotions = emotions; - } - public String getActions() { - return actions; - } - - public String getPoses() { - return poses; - } - - public void setPoses(String poses) { - this.poses = poses; - } - - public void setActions(String actions) { - this.actions = actions; - } - public boolean getTalking() { - return talking; - } - - public void setTalking(boolean talking) { - this.talking = talking; - } + public String mediaId; + public String name; + public String type; + public String media; + public String emotions; + public String actions; + public String poses; + public boolean hd; + public boolean talking; + + public void parseXML(Element element) { + super.parseXML(element); + + this.mediaId = element.getAttribute("mediaId"); + this.name = element.getAttribute("name"); + this.type = element.getAttribute("type"); + this.media = element.getAttribute("media"); + this.emotions = element.getAttribute("emotions"); + this.actions = element.getAttribute("actions"); + this.poses = element.getAttribute("poses"); + this.hd = Boolean.valueOf(element.getAttribute("hd")); + this.talking = Boolean.valueOf(element.getAttribute("talking")); + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public boolean getHD() { + return hd; + } + + public boolean isImage() { + return this.type.contains("image") || this.type.isEmpty(); + } + + public boolean isVideo() { + return this.type != null && this.type.indexOf("video") != -1; + } + + public boolean isAudio() { + return this.type != null && this.type.indexOf("audio") != -1; + } + + public String getType() { + return type; + } + + public String getEmotions() { + return emotions; + } + + public void setEmotions(String emotions) { + this.emotions = emotions; + } + + public String getActions() { + return actions; + } + + public String getPoses() { + return poses; + } + + public void setPoses(String poses) { + this.poses = poses; + } + + public void setActions(String actions) { + this.actions = actions; + } + + public boolean getTalking() { + return talking; + } + + public void setTalking(boolean talking) { + this.talking = talking; + } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java index b77fbfc..67ee97b 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java @@ -21,50 +21,50 @@ import java.io.StringWriter; * DTO for XML browse options. */ public class BrowseConfig extends Config { - public String type; - public String typeFilter; - public String category; - public String tag; - public String filter; - public String userFilter; - public String sort; - public String restrict; - public String page; - public String contentRating; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String type; + public String typeFilter; + public String category; + public String tag; + public String filter; + public String userFilter; + public String sort; + public String restrict; + public String page; + public String contentRating; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java index 48c4e82..2144ffb 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java @@ -23,53 +23,53 @@ import java.io.StringWriter; * DTO for XML channel config. */ public class ChannelConfig extends WebMediumConfig { - public String type; - public String videoAccessMode; - public String audioAccessMode; - public String messages; - public String usersOnline; - public String adminsOnline; + public String type; + public String videoAccessMode; + public String audioAccessMode; + public String messages; + public String usersOnline; + public String adminsOnline; - @Override - public String getType() { - return "channel"; - } + @Override + public String getType() { + return "channel"; + } - @Override - public String stats() { - return this.usersOnline + " users online, " + this.adminsOnline + " admins"; - } - - public WebMediumConfig credentials() { - ChannelConfig config = new ChannelConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.type = element.getAttribute("type"); - this.videoAccessMode = element.getAttribute("videoAccessMode"); - this.audioAccessMode = element.getAttribute("audioAccessMode"); - this.messages = element.getAttribute("messages"); - this.usersOnline = element.getAttribute("usersOnline"); - this.adminsOnline = element.getAttribute("adminsOnline"); - } + @Override + public String stats() { + return this.usersOnline + " users online, " + this.adminsOnline + " admins"; + } + + public WebMediumConfig credentials() { + ChannelConfig config = new ChannelConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.type = element.getAttribute("type"); + this.videoAccessMode = element.getAttribute("videoAccessMode"); + this.audioAccessMode = element.getAttribute("audioAccessMode"); + this.messages = element.getAttribute("messages"); + this.usersOnline = element.getAttribute("usersOnline"); + this.adminsOnline = element.getAttribute("adminsOnline"); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java index ec58150..ef3a17f 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java @@ -24,73 +24,73 @@ import java.io.StringWriter; /** * DTO for XML chat config. */ -public class ChatConfig extends Config { - public String conversation; - public boolean correction; - public boolean offensive; - public boolean disconnect; - public String emote; - public String action; - public String message; - public boolean speak; - public boolean includeQuestion; - public boolean avatarHD; - public String avatarFormat; - public String avatar; - public String language; - public String voice; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } +public class ChatConfig extends Config { + public String conversation; + public boolean correction; + public boolean offensive; + public boolean disconnect; + public String emote; + public String action; + public String message; + public boolean speak; + public boolean includeQuestion; + public boolean avatarHD; + public String avatarFormat; + public String avatar; + public String language; + public String voice; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.message != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.message)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java index 294a617..b53a7b9 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java @@ -23,81 +23,81 @@ import org.w3c.dom.Node; /** * DTO for XML chat config. */ -public class ChatResponse extends Config { - public String conversation; - public String message; - public String question; - public String emote; - public String action; - public String pose; - public String command; - public String avatar; - public String avatar2; - public String avatar3; - public String avatar4; - public String avatar5; - public String avatarType; - public String avatarTalk; - public String avatarTalkType; - public String avatarAction; - public String avatarActionType; - public String avatarActionAudio; - public String avatarActionAudioType; - public String avatarAudio; - public String avatarAudioType; - public String avatarBackground; - public String speech; - - public boolean isVideo() { - return this.avatarType != null && this.avatarType.indexOf("video") != -1; - } - - public boolean isVideoTalk() { - return this.avatarTalkType != null && this.avatarTalkType.indexOf("video") != -1; - } +public class ChatResponse extends Config { + public String conversation; + public String message; + public String question; + public String emote; + public String action; + public String pose; + public String command; + public String avatar; + public String avatar2; + public String avatar3; + public String avatar4; + public String avatar5; + public String avatarType; + public String avatarTalk; + public String avatarTalkType; + public String avatarAction; + public String avatarActionType; + public String avatarActionAudio; + public String avatarActionAudioType; + public String avatarAudio; + public String avatarAudioType; + public String avatarBackground; + public String speech; - public void parseXML(Element element) { - this.conversation = element.getAttribute("conversation"); - this.emote = element.getAttribute("emote"); - this.action = element.getAttribute("action"); - this.pose = element.getAttribute("pose"); - this.avatar = element.getAttribute("avatar"); - this.avatar2 = element.getAttribute("avatar2"); - this.avatar3 = element.getAttribute("avatar3"); - this.avatar4 = element.getAttribute("avatar4"); - this.avatar5 = element.getAttribute("avatar5"); - this.avatarType = element.getAttribute("avatarType"); - this.avatarTalk = element.getAttribute("avatarTalk"); - this.avatarTalkType = element.getAttribute("avatarTalkType"); - this.avatarAction = element.getAttribute("avatarAction"); - this.avatarActionType = element.getAttribute("avatarActionType"); - this.avatarActionAudio = element.getAttribute("avatarActionAudio"); - this.avatarActionAudioType = element.getAttribute("avatarActionAudioType"); - this.avatarAudio = element.getAttribute("avatarAudio"); - this.avatarAudioType = element.getAttribute("avatarAudioType"); - this.avatarBackground = element.getAttribute("avatarBackground"); - this.speech = element.getAttribute("speech"); - this.command = element.getAttribute("command"); + public boolean isVideo() { + return this.avatarType != null && this.avatarType.indexOf("video") != -1; + } - Node node = element.getElementsByTagName("message").item(0); - if (node != null) { - this.message = node.getTextContent(); - } - node = element.getElementsByTagName("question").item(0); - if (node != null) { - this.question = node.getTextContent(); - } - } - - public ZSONObject getCommand(){ - if (this.command == null || this.command.equals("")){ - return null; - } - try { - return new ZSONObject(); - } catch (ZSONException exception) { - exception.printStackTrace(); - } - return null; - } + public boolean isVideoTalk() { + return this.avatarTalkType != null && this.avatarTalkType.indexOf("video") != -1; + } + + public void parseXML(Element element) { + this.conversation = element.getAttribute("conversation"); + this.emote = element.getAttribute("emote"); + this.action = element.getAttribute("action"); + this.pose = element.getAttribute("pose"); + this.avatar = element.getAttribute("avatar"); + this.avatar2 = element.getAttribute("avatar2"); + this.avatar3 = element.getAttribute("avatar3"); + this.avatar4 = element.getAttribute("avatar4"); + this.avatar5 = element.getAttribute("avatar5"); + this.avatarType = element.getAttribute("avatarType"); + this.avatarTalk = element.getAttribute("avatarTalk"); + this.avatarTalkType = element.getAttribute("avatarTalkType"); + this.avatarAction = element.getAttribute("avatarAction"); + this.avatarActionType = element.getAttribute("avatarActionType"); + this.avatarActionAudio = element.getAttribute("avatarActionAudio"); + this.avatarActionAudioType = element.getAttribute("avatarActionAudioType"); + this.avatarAudio = element.getAttribute("avatarAudio"); + this.avatarAudioType = element.getAttribute("avatarAudioType"); + this.avatarBackground = element.getAttribute("avatarBackground"); + this.speech = element.getAttribute("speech"); + this.command = element.getAttribute("command"); + + Node node = element.getElementsByTagName("message").item(0); + if (node != null) { + this.message = node.getTextContent(); + } + node = element.getElementsByTagName("question").item(0); + if (node != null) { + this.question = node.getTextContent(); + } + } + + public ZSONObject getCommand() { + if (this.command == null || this.command.equals("")) { + return null; + } + try { + return new ZSONObject(); + } catch (ZSONException exception) { + exception.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/Config.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/Config.java index 0d761c6..99478fe 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/Config.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/Config.java @@ -24,63 +24,63 @@ import java.io.StringWriter; * DTO for XML config. */ public class Config implements Cloneable { - public String application; - public String domain; - public String user; - public String token; - public String instance; - public String supertype; - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException exception) { - throw new Error(exception); - } - } - - public void addCredentials(SDKConnection connection) { - this.application = connection.getCredentials().getApplicationId(); - if (this.user == null && connection.getUser() != null) { - this.user = connection.getUser().user; - this.token = connection.getUser().token; - } - if (this.domain == null && connection.getDomain() != null) { - this.domain = connection.getDomain().id; - } - } - - public String toXML() { - return ""; - } - - public void parseXML(Element element) { - this.application = element.getAttribute("application"); - this.domain = element.getAttribute("domain"); - this.user = element.getAttribute("user"); - this.token = element.getAttribute("token"); - this.instance = element.getAttribute("instance"); - this.supertype = element.getAttribute("type"); - } - - public void writeCredentials(StringWriter writer) { - if (this.user != null && this.user.length() > 0) { - writer.write(" user=\"" + this.user + "\""); - } - if (this.token != null && this.token.length() > 0) { - writer.write(" token=\"" + this.token + "\""); - } - if (this.supertype != null && !this.supertype.equals("")) { - writer.write(" type=\"" + this.supertype + "\""); - } - if (this.instance != null && !this.instance.equals("")) { - writer.write(" instance=\"" + this.instance + "\""); - } - if (this.application != null && !this.application.equals("")) { - writer.write(" application=\"" + this.application + "\""); - } - if (this.domain != null && !this.domain.equals("")) { - writer.write(" domain=\"" + this.domain + "\""); - } - } + public String application; + public String domain; + public String user; + public String token; + public String instance; + public String supertype; + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException exception) { + throw new Error(exception); + } + } + + public void addCredentials(SDKConnection connection) { + this.application = connection.getCredentials().getApplicationId(); + if (this.user == null && connection.getUser() != null) { + this.user = connection.getUser().user; + this.token = connection.getUser().token; + } + if (this.domain == null && connection.getDomain() != null) { + this.domain = connection.getDomain().id; + } + } + + public String toXML() { + return ""; + } + + public void parseXML(Element element) { + this.application = element.getAttribute("application"); + this.domain = element.getAttribute("domain"); + this.user = element.getAttribute("user"); + this.token = element.getAttribute("token"); + this.instance = element.getAttribute("instance"); + this.supertype = element.getAttribute("type"); + } + + public void writeCredentials(StringWriter writer) { + if (this.user != null && this.user.length() > 0) { + writer.write(" user=\"" + this.user + "\""); + } + if (this.token != null && this.token.length() > 0) { + writer.write(" token=\"" + this.token + "\""); + } + if (this.supertype != null && !this.supertype.equals("")) { + writer.write(" type=\"" + this.supertype + "\""); + } + if (this.instance != null && !this.instance.equals("")) { + writer.write(" instance=\"" + this.instance + "\""); + } + if (this.application != null && !this.application.equals("")) { + writer.write(" application=\"" + this.application + "\""); + } + if (this.domain != null && !this.domain.equals("")) { + writer.write(" domain=\"" + this.domain + "\""); + } + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java index 72ab06a..b35125f 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java @@ -23,43 +23,43 @@ import java.io.StringWriter; * DTO for XML forum config. */ public class ForumConfig extends WebMediumConfig { - public String replyAccessMode; - public String postAccessMode; - public String posts; - - public String getType() { - return "forum"; - } + public String replyAccessMode; + public String postAccessMode; + public String posts; - @Override - public String stats() { - return this.posts + " posts"; - } - - public WebMediumConfig credentials() { - ForumConfig config = new ForumConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.replyAccessMode = element.getAttribute("replyAccessMode"); - this.postAccessMode = element.getAttribute("postAccessMode"); - this.posts = element.getAttribute("posts"); - } + public String getType() { + return "forum"; + } + + @Override + public String stats() { + return this.posts + " posts"; + } + + public WebMediumConfig credentials() { + ForumConfig config = new ForumConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.replyAccessMode = element.getAttribute("replyAccessMode"); + this.postAccessMode = element.getAttribute("postAccessMode"); + this.posts = element.getAttribute("posts"); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java index de1f166..04ddbae 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java @@ -22,59 +22,61 @@ import java.io.StringWriter; /** * DTO for XML graphic config. */ -public class GraphicConfig extends WebMediumConfig{ - public String media; - public String fileName; - public String fileType; - - - @Override - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } +public class GraphicConfig extends WebMediumConfig { + public String media; + public String fileName; + public String fileType; - @Override - public String getType() { - return "graphic"; - } - @Override - public WebMediumConfig credentials() { - GraphicConfig config = new GraphicConfig(); - config.id = this.id; - return config; - } - public void parseXML(Element element) { - super.parseXML(element); - this.media = element.getAttribute("media"); - this.fileName = element.getAttribute("fileName"); - this.fileType = element.getAttribute("fileType"); + @Override + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + @Override + public String getType() { + return "graphic"; + } + + @Override + public WebMediumConfig credentials() { + GraphicConfig config = new GraphicConfig(); + config.id = this.id; + return config; + } + + public void parseXML(Element element) { + super.parseXML(element); + this.media = element.getAttribute("media"); + this.fileName = element.getAttribute("fileName"); + this.fileType = element.getAttribute("fileType"); // Node node = element.getElementsByTagName("media").item(0); // if (node != null) { // this.media = node.getTextContent(); // } - } - public boolean isVideo() { - return this.fileType != null && this.fileType.indexOf("video") != -1; - - } - - public boolean isAudio() { - return this.fileType != null && this.fileType.indexOf("audio") != -1; - } + } + + public boolean isVideo() { + return this.fileType != null && this.fileType.indexOf("video") != -1; + + } + + public boolean isAudio() { + return this.fileType != null && this.fileType.indexOf("audio") != -1; + } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java index a724992..05d43ad 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java @@ -24,69 +24,69 @@ import java.io.StringWriter; * DTO for XML bot instance config. */ public class InstanceConfig extends WebMediumConfig { - public String size; - public String instanceAvatar; - public boolean allowForking; - public boolean hasAPI; - public String template; - public int rank; - public int wins; - public int losses; - - public String getType() { - return "instance"; - } + public String size; + public String instanceAvatar; + public boolean allowForking; + public boolean hasAPI; + public String template; + public int rank; + public int wins; + public int losses; - @Override - public String stats() { - return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month"; - } + public String getType() { + return "instance"; + } - @Override - public InstanceConfig credentials() { - InstanceConfig config = new InstanceConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - writer.write(this.template); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.allowForking = Boolean.valueOf(element.getAttribute("allowForking")); - this.hasAPI = Boolean.valueOf(element.getAttribute("hasAPI")); - this.size = element.getAttribute("size"); - this.instanceAvatar = element.getAttribute("instanceAvatar"); - if (element.getAttribute("rank") != null && element.getAttribute("rank").trim().length() > 0) { - this.rank = Integer.valueOf(element.getAttribute("rank")); - } - if (element.getAttribute("wins") != null && element.getAttribute("wins").trim().length() > 0) { - this.wins = Integer.valueOf(element.getAttribute("wins")); - } - if (element.getAttribute("losses") != null && element.getAttribute("losses").trim().length() > 0) { - this.losses = Integer.valueOf(element.getAttribute("losses")); - } - - Node node = element.getElementsByTagName("template").item(0); - if (node != null) { - this.template = node.getTextContent(); - } - } + @Override + public String stats() { + return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month"; + } + + @Override + public InstanceConfig credentials() { + InstanceConfig config = new InstanceConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + writer.write(this.template); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.allowForking = Boolean.valueOf(element.getAttribute("allowForking")); + this.hasAPI = Boolean.valueOf(element.getAttribute("hasAPI")); + this.size = element.getAttribute("size"); + this.instanceAvatar = element.getAttribute("instanceAvatar"); + if (element.getAttribute("rank") != null && element.getAttribute("rank").trim().length() > 0) { + this.rank = Integer.valueOf(element.getAttribute("rank")); + } + if (element.getAttribute("wins") != null && element.getAttribute("wins").trim().length() > 0) { + this.wins = Integer.valueOf(element.getAttribute("wins")); + } + if (element.getAttribute("losses") != null && element.getAttribute("losses").trim().length() > 0) { + this.losses = Integer.valueOf(element.getAttribute("losses")); + } + + Node node = element.getElementsByTagName("template").item(0); + if (node != null) { + this.template = node.getTextContent(); + } + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java index 8342f28..8e0bb10 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java @@ -31,158 +31,159 @@ import java.util.Objects; * DTO for XML issue config. */ public class IssueConfig extends Config { - public String id; - public String title; - public String priority; - public String summary; - public String details; - public String detailsText; - public String tracker; - public String tags; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public boolean isAdmin; - public boolean isFlagged; - public String flaggedReason; - public boolean isPriority; - public String creator; - public String creationDate; - public String views; - public String dailyViews; - public String weeklyViews; - public String monthlyViews; - public String avatar; - - public boolean equals(Object object) { - if (object instanceof IssueConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((IssueConfig)object).id); - } - return false; - } + public String id; + public String title; + public String priority; + public String summary; + public String details; + public String detailsText; + public String tracker; + public String tags; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public boolean isAdmin; + public boolean isFlagged; + public String flaggedReason; + public boolean isPriority; + public String creator; + public String creationDate; + public String views; + public String dailyViews; + public String weeklyViews; + public String monthlyViews; + public String avatar; - @Override - public int hashCode() { - return Objects.hash(id, title, priority, summary, details, detailsText, tracker, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isPriority, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, avatar); - } + public boolean equals(Object object) { + if (object instanceof IssueConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((IssueConfig) object).id); + } + return false; + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + @Override + public int hashCode() { + return Objects.hash(id, title, priority, summary, details, detailsText, tracker, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isPriority, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, avatar); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.title != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.title)); - writer.write(""); - } - if (this.details != null) { - String text = this.details; - writer.write("
"); - writer.write(Utils.escapeHTML(text)); - writer.write("
"); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.tracker = element.getAttribute("tracker"); - this.priority = element.getAttribute("priority"); - this.views = element.getAttribute("views"); - this.dailyViews = element.getAttribute("dailyViews"); - this.weeklyViews = element.getAttribute("weeklyViews"); - this.monthlyViews = element.getAttribute("monthlyViews"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isPriority = Boolean.valueOf(element.getAttribute("isPriority")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("summary").item(0); - if (node != null) { - this.summary = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("detailsText").item(0); - if (node != null) { - this.detailsText = node.getTextContent(); - } - node = element.getElementsByTagName("title").item(0); - if (node != null) { - this.title = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - } - public IssueConfig credentials() { - IssueConfig config = new IssueConfig(); - config.id = this.id; - return config; - } + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.title != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.title)); + writer.write(""); + } + if (this.details != null) { + String text = this.details; + writer.write("
"); + writer.write(Utils.escapeHTML(text)); + writer.write("
"); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.tracker = element.getAttribute("tracker"); + this.priority = element.getAttribute("priority"); + this.views = element.getAttribute("views"); + this.dailyViews = element.getAttribute("dailyViews"); + this.weeklyViews = element.getAttribute("weeklyViews"); + this.monthlyViews = element.getAttribute("monthlyViews"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isPriority = Boolean.valueOf(element.getAttribute("isPriority")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("summary").item(0); + if (node != null) { + this.summary = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("detailsText").item(0); + if (node != null) { + this.detailsText = node.getTextContent(); + } + node = element.getElementsByTagName("title").item(0); + if (node != null) { + this.title = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + } + + public IssueConfig credentials() { + IssueConfig config = new IssueConfig(); + config.id = this.id; + return config; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayTimestamp(date); + } catch (Exception exception) { + return creationDate; + } + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java index 9490aca..aead02f 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java @@ -24,96 +24,98 @@ import java.io.StringWriter; * DTO for XML voice config. */ public class LearningConfig extends Config { - - public String learningMode; - public String learningRate; - public String correctionMode; - public boolean enableComprehension; - public boolean enableEmoting; - public boolean enableEmotions; - public boolean enableConsciousness; - public boolean enableWiktionary; - public boolean enableResponseMatch; - public boolean learnGrammar; - public boolean synthesizeResponse; - public boolean fixFormulaCase; - public boolean checkExactMatchFirst; - public int scriptTimeout; - public int responseMatchTimeout; - public String conversationMatchPercentage; - public String discussionMatchPercentage; - - public void parseXML(Element element) { - super.parseXML(element); - - this.learningMode = element.getAttribute("learningMode"); - this.learningRate = element.getAttribute("learningRate"); - this.correctionMode = element.getAttribute("correctionMode"); - this.enableComprehension = Boolean.valueOf(element.getAttribute("enableComprehension")); - this.enableEmoting = Boolean.valueOf(element.getAttribute("enableEmoting")); - this.enableEmotions = Boolean.valueOf(element.getAttribute("enableEmotions")); - this.enableConsciousness = Boolean.valueOf(element.getAttribute("enableConsciousness")); - this.enableWiktionary = Boolean.valueOf(element.getAttribute("enableWiktionary")); - this.enableResponseMatch = Boolean.valueOf(element.getAttribute("enableResponseMatch")); - this.learnGrammar = Boolean.valueOf(element.getAttribute("learnGrammar")); - this.synthesizeResponse = Boolean.valueOf(element.getAttribute("synthesizeResponse")); - this.fixFormulaCase = Boolean.valueOf(element.getAttribute("fixFormulaCase")); - this.checkExactMatchFirst = Boolean.valueOf(element.getAttribute("checkExactMatchFirst")); - String value = element.getAttribute("scriptTimeout"); - if (value != null && value.length() > 0) { - try { - this.scriptTimeout = Integer.valueOf(value); - } catch (Exception ignore) {} - } - value = element.getAttribute("responseMatchTimeout"); - if (value != null && value.length() > 0) { - try { - this.responseMatchTimeout = Integer.valueOf(value); - } catch (Exception ignore) {} - } - this.conversationMatchPercentage = element.getAttribute("conversationMatchPercentage"); - this.discussionMatchPercentage = element.getAttribute("discussionMatchPercentage"); - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(" 0) { - writer.write(" conversationMatchPercentage=\"" + this.conversationMatchPercentage + "\""); - } - if (this.discussionMatchPercentage != null && this.discussionMatchPercentage.length() > 0) { - writer.write(" discussionMatchPercentage=\"" + this.discussionMatchPercentage + "\""); - } - if (this.learningRate != null && this.learningRate.length() > 0) { - writer.write(" learningRate=\"" + this.learningRate + "\""); - } - - writer.write("/>"); - return writer.toString(); - } + public void parseXML(Element element) { + super.parseXML(element); + + this.learningMode = element.getAttribute("learningMode"); + this.learningRate = element.getAttribute("learningRate"); + this.correctionMode = element.getAttribute("correctionMode"); + this.enableComprehension = Boolean.valueOf(element.getAttribute("enableComprehension")); + this.enableEmoting = Boolean.valueOf(element.getAttribute("enableEmoting")); + this.enableEmotions = Boolean.valueOf(element.getAttribute("enableEmotions")); + this.enableConsciousness = Boolean.valueOf(element.getAttribute("enableConsciousness")); + this.enableWiktionary = Boolean.valueOf(element.getAttribute("enableWiktionary")); + this.enableResponseMatch = Boolean.valueOf(element.getAttribute("enableResponseMatch")); + this.learnGrammar = Boolean.valueOf(element.getAttribute("learnGrammar")); + this.synthesizeResponse = Boolean.valueOf(element.getAttribute("synthesizeResponse")); + this.fixFormulaCase = Boolean.valueOf(element.getAttribute("fixFormulaCase")); + this.checkExactMatchFirst = Boolean.valueOf(element.getAttribute("checkExactMatchFirst")); + String value = element.getAttribute("scriptTimeout"); + if (value != null && value.length() > 0) { + try { + this.scriptTimeout = Integer.valueOf(value); + } catch (Exception ignore) { + } + } + value = element.getAttribute("responseMatchTimeout"); + if (value != null && value.length() > 0) { + try { + this.responseMatchTimeout = Integer.valueOf(value); + } catch (Exception ignore) { + } + } + this.conversationMatchPercentage = element.getAttribute("conversationMatchPercentage"); + this.discussionMatchPercentage = element.getAttribute("discussionMatchPercentage"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(" 0) { + writer.write(" conversationMatchPercentage=\"" + this.conversationMatchPercentage + "\""); + } + if (this.discussionMatchPercentage != null && this.discussionMatchPercentage.length() > 0) { + writer.write(" discussionMatchPercentage=\"" + this.discussionMatchPercentage + "\""); + } + if (this.learningRate != null && this.learningRate.length() > 0) { + writer.write(" learningRate=\"" + this.learningRate + "\""); + } + + writer.write("/>"); + return writer.toString(); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java index 36aa789..4f16f33 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java @@ -12,87 +12,88 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + package org.botlibre.sdk.config; public class OfflineTemplateConfig { - private int imageId; - private int id_; - private String id; - private String title; - private String dec; - - public OfflineTemplateConfig(){ + private int imageId; + private int id_; + private String id; + private String title; + private String dec; + + public OfflineTemplateConfig() { + + } + + public OfflineTemplateConfig(int imageId, String title, String dec, String id) { + this.setImageId(imageId); + this.setTitle(title); + this.setDec(dec); + this.setId(id); + } + + public OfflineTemplateConfig(int imageId, String title, String dec, String id, int id_) { + this.setImageId(imageId); + this.setTitle(title); + this.setDec(dec); + this.setId(id); + this.setId_(id_); + } + + public int getImageId() { + return imageId; + } - } - - public OfflineTemplateConfig(int imageId, String title, String dec, String id){ - this.setImageId(imageId); - this.setTitle(title); - this.setDec(dec); - this.setId(id); - } - public OfflineTemplateConfig(int imageId, String title, String dec, String id,int id_){ - this.setImageId(imageId); - this.setTitle(title); - this.setDec(dec); - this.setId(id); - this.setId_(id_); - } - public int getImageId() { - return imageId; - } + public void setImageId(int imageId) { + this.imageId = imageId; + } - public void setImageId(int imageId) { - this.imageId = imageId; - } + public String getTitle() { + return title; + } - public String getTitle() { - return title; - } + public void setTitle(String title) { + this.title = title; + } + @Override + public String toString() { + return title + "\n" + dec; - public void setTitle(String title) { - this.title = title; - } - - @Override - public String toString(){ - return title + "\n" + dec; - - } + } - public String getDec() { - return dec; - } + public String getDec() { + return dec; + } - public void setDec(String dec) { - this.dec = dec; - } + public void setDec(String dec) { + this.dec = dec; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public int getId_() { - return id_; - } + public int getId_() { + return id_; + } - public void setId_(int id_) { - this.id_ = id_; - } + public void setId_(int id_) { + this.id_ = id_; + } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java index dda7ac3..423d0a1 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java @@ -28,175 +28,175 @@ import java.util.Objects; /** * DTO for XML response config. */ -public class ResponseConfig extends Config { - public String questionId; - public String responseId; - public String question; - public String response; - public String previous; - public String onRepeat; - public String label; - public String topic; - public String keywords; - public String required; - public String emotions; - public String actions; - public String poses; - public boolean noRepeat; - public boolean requirePrevious; - public boolean requireTopic; - public boolean flagged; - public String correctness; - public String command; +public class ResponseConfig extends Config { + public String questionId; + public String responseId; + public String question; + public String response; + public String previous; + public String onRepeat; + public String label; + public String topic; + public String keywords; + public String required; + public String emotions; + public String actions; + public String poses; + public boolean noRepeat; + public boolean requirePrevious; + public boolean requireTopic; + public boolean flagged; + public String correctness; + public String command; - public ResponseConfig() { - - } - - public boolean equals(Object object) { - if (this == object) { - return true; - } - if ((object instanceof ResponseConfig) && (this.responseId != null) && !this.responseId.isEmpty() - && this.responseId.equals(((ResponseConfig)object).responseId)) { - if (((this.questionId == null) || this.questionId.isEmpty()) - && (((ResponseConfig)object).questionId == null) || ((ResponseConfig)object).questionId.isEmpty()) { - return true; - } - if ((this.questionId != null) && !this.questionId.isEmpty() - && this.questionId.equals(((ResponseConfig)object).questionId)) { - return true; - } - } - return super.equals(object); - } + public ResponseConfig() { - @Override - public int hashCode() { - return Objects.hash(questionId, responseId, question, response, previous, onRepeat, label, topic, keywords, required, emotions, actions, poses, noRepeat, requirePrevious, requireTopic, flagged, correctness, command); - } + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + public boolean equals(Object object) { + if (this == object) { + return true; + } + if ((object instanceof ResponseConfig) && (this.responseId != null) && !this.responseId.isEmpty() + && this.responseId.equals(((ResponseConfig) object).responseId)) { + if (((this.questionId == null) || this.questionId.isEmpty()) + && (((ResponseConfig) object).questionId == null) || ((ResponseConfig) object).questionId.isEmpty()) { + return true; + } + if ((this.questionId != null) && !this.questionId.isEmpty() + && this.questionId.equals(((ResponseConfig) object).questionId)) { + return true; + } + } + return super.equals(object); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.question != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.question)); - writer.write(""); - } - if (this.response != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.response)); - writer.write(""); - } - if (this.previous != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.previous)); - writer.write(""); - } - if (this.onRepeat != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.onRepeat)); - writer.write(""); - } - if (this.command != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.command)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.questionId = element.getAttribute("questionId"); - this.responseId = element.getAttribute("responseId"); - this.label = element.getAttribute("label"); - this.topic = element.getAttribute("topic"); - this.keywords = element.getAttribute("keywords"); - this.required = element.getAttribute("required"); - this.emotions = element.getAttribute("emotions"); - this.actions = element.getAttribute("actions"); - this.poses = element.getAttribute("poses"); - this.supertype = element.getAttribute("type"); - this.correctness = element.getAttribute("correctness"); - if (element.getAttribute("noRepeat") != null) { - this.noRepeat = Boolean.valueOf(element.getAttribute("noRepeat")); - } - if (element.getAttribute("flagged") != null) { - this.flagged = Boolean.valueOf(element.getAttribute("flagged")); - } - if (element.getAttribute("requireTopic") != null) { - this.requireTopic = Boolean.valueOf(element.getAttribute("requireTopic")); - } - if (element.getAttribute("requirePrevious") != null) { - this.requirePrevious = Boolean.valueOf(element.getAttribute("requirePrevious")); - } - - Node node = element.getElementsByTagName("question").item(0); - if (node != null) { - this.question = node.getTextContent(); - } - node = element.getElementsByTagName("response").item(0); - if (node != null) { - this.response = node.getTextContent(); - } - node = element.getElementsByTagName("command").item(0); - if (node != null) { - this.command = node.getTextContent(); - this.command = this.command.replace(""", "\""); - } - } - - public ZSONObject getCommand(){ - if (this.command == null || this.command.equals("")){ - return null; - } - try { - return new ZSONObject(); - } catch (ZSONException e) { - e.printStackTrace(); - } - return null; - } + @Override + public int hashCode() { + return Objects.hash(questionId, responseId, question, response, previous, onRepeat, label, topic, keywords, required, emotions, actions, poses, noRepeat, requirePrevious, requireTopic, flagged, correctness, command); + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } + + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.question != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.question)); + writer.write(""); + } + if (this.response != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.response)); + writer.write(""); + } + if (this.previous != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.previous)); + writer.write(""); + } + if (this.onRepeat != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.onRepeat)); + writer.write(""); + } + if (this.command != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.command)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.questionId = element.getAttribute("questionId"); + this.responseId = element.getAttribute("responseId"); + this.label = element.getAttribute("label"); + this.topic = element.getAttribute("topic"); + this.keywords = element.getAttribute("keywords"); + this.required = element.getAttribute("required"); + this.emotions = element.getAttribute("emotions"); + this.actions = element.getAttribute("actions"); + this.poses = element.getAttribute("poses"); + this.supertype = element.getAttribute("type"); + this.correctness = element.getAttribute("correctness"); + if (element.getAttribute("noRepeat") != null) { + this.noRepeat = Boolean.valueOf(element.getAttribute("noRepeat")); + } + if (element.getAttribute("flagged") != null) { + this.flagged = Boolean.valueOf(element.getAttribute("flagged")); + } + if (element.getAttribute("requireTopic") != null) { + this.requireTopic = Boolean.valueOf(element.getAttribute("requireTopic")); + } + if (element.getAttribute("requirePrevious") != null) { + this.requirePrevious = Boolean.valueOf(element.getAttribute("requirePrevious")); + } + + Node node = element.getElementsByTagName("question").item(0); + if (node != null) { + this.question = node.getTextContent(); + } + node = element.getElementsByTagName("response").item(0); + if (node != null) { + this.response = node.getTextContent(); + } + node = element.getElementsByTagName("command").item(0); + if (node != null) { + this.command = node.getTextContent(); + this.command = this.command.replace(""", "\""); + } + } + + public ZSONObject getCommand() { + if (this.command == null || this.command.equals("")) { + return null; + } + try { + return new ZSONObject(); + } catch (ZSONException e) { + e.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java index 36e43c0..a316f90 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java @@ -20,45 +20,44 @@ import org.w3c.dom.Element; import java.io.StringWriter; public class ScriptConfig extends WebMediumConfig { - public String language; - public String version; - - public String getType() { - return "script"; - } - - public WebMediumConfig credentials() { - ScriptConfig config = new ScriptConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - return writer.toString(); - } - - public void parseXML(Element element){ - super.parseXML(element); - this.language = element.getAttribute("language"); - this.version = element.getAttribute("version"); - } - - @Override - public String toString() { - return this.name; - } - + public String language; + public String version; + + public String getType() { + return "script"; + } + + public WebMediumConfig credentials() { + ScriptConfig config = new ScriptConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.language = element.getAttribute("language"); + this.version = element.getAttribute("version"); + } + + @Override + public String toString() { + return this.name; + } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java index d44891c..c16c238 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java @@ -22,87 +22,86 @@ import org.w3c.dom.Node; import java.io.StringWriter; -public class ScriptSourceConfig extends Config{ - public String id; - public String creationDate; - public String updateDate; - public boolean version; - public String versionName; - public String creator; - public String source; +public class ScriptSourceConfig extends Config { + public String id; + public String creationDate; + public String updateDate; + public boolean version; + public String versionName; + public String creator; + public String source; - public ScriptSourceConfig credentials() { - ScriptSourceConfig config = new ScriptSourceConfig(); - config.creator = this.creator; - return config; - } + public ScriptSourceConfig credentials() { + ScriptSourceConfig config = new ScriptSourceConfig(); + config.creator = this.creator; + return config; + } - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.source != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.source)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } + writer.write(">"); - public void parseXML(Element element){ - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.updateDate = element.getAttribute("updateDate"); - this.version = Boolean.valueOf(element.getAttribute("version")); - this.versionName = element.getAttribute("versionName"); - this.creator = element.getAttribute("creator"); - - Node node = element.getElementsByTagName("source").item(0); - if (node != null) { - this.source = node.getTextContent(); - } - } + if (this.source != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.source)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } - public String getNextVersion() { - if (this.source == null) { - return "0.1"; - } + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.creationDate = element.getAttribute("creationDate"); + this.updateDate = element.getAttribute("updateDate"); + this.version = Boolean.valueOf(element.getAttribute("version")); + this.versionName = element.getAttribute("versionName"); + this.creator = element.getAttribute("creator"); - String version = this.source; - int index = version.lastIndexOf('.'); - if (index != -1) { - String major = version.substring(0, index); - String minor = version.substring(index + 1, version.length()); - try { - int value = Integer.valueOf(minor); - version = major + "." + (value + 1); - } - catch (NumberFormatException ignore) { - } - } - return version; - } + Node node = element.getElementsByTagName("source").item(0); + if (node != null) { + this.source = node.getTextContent(); + } + } + + public String getNextVersion() { + if (this.source == null) { + return "0.1"; + } + + String version = this.source; + int index = version.lastIndexOf('.'); + if (index != -1) { + String major = version.substring(0, index); + String minor = version.substring(index + 1, version.length()); + try { + int value = Integer.valueOf(minor); + version = major + "." + (value + 1); + } catch (NumberFormatException ignore) { + } + } + return version; + } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java index d14869d..f4a2d72 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java @@ -26,129 +26,129 @@ import java.util.Objects; * DTO for XML user creation config. */ public class UserConfig extends Config { - public String password; - public String newPassword; - public String hint; - public String name; - public boolean showName; - public String email; - public String website; - public String bio; - public boolean over18; - public String avatar; - - public String connects; - public String bots; - public String posts; - public String messages; - public String forums; - public String scripts; - public String graphics; - public String avatars; - public String domains; - public String channels; - - public String joined; - public String lastConnect; - public String type; - public boolean isFlagged; - public String flaggedReason; + public String password; + public String newPassword; + public String hint; + public String name; + public boolean showName; + public String email; + public String website; + public String bio; + public boolean over18; + public String avatar; - public void addCredentials(SDKConnection connection) { - this.application = connection.getCredentials().getApplicationId(); - if (connection.getDomain() != null) { - this.domain = connection.getDomain().id; - } - } - - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (!(object instanceof UserConfig)) { - return false; - } - return this.user != null && this.user.equals(((UserConfig)object).user); - } + public String connects; + public String bots; + public String posts; + public String messages; + public String forums; + public String scripts; + public String graphics; + public String avatars; + public String domains; + public String channels; - @Override - public int hashCode() { - return Objects.hash(password, newPassword, hint, name, showName, email, website, bio, over18, avatar, connects, bots, posts, messages, forums, scripts, graphics, avatars, domains, channels, joined, lastConnect, type, isFlagged, flaggedReason); - } + public String joined; + public String lastConnect; + public String type; + public boolean isFlagged; + public String flaggedReason; + + public void addCredentials(SDKConnection connection) { + this.application = connection.getCredentials().getApplicationId(); + if (connection.getDomain() != null) { + this.domain = connection.getDomain().id; + } + } + + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (!(object instanceof UserConfig)) { + return false; + } + return this.user != null && this.user.equals(((UserConfig) object).user); + } + + @Override + public int hashCode() { + return Objects.hash(password, newPassword, hint, name, showName, email, website, bio, over18, avatar, connects, bots, posts, messages, forums, scripts, graphics, avatars, domains, channels, joined, lastConnect, type, isFlagged, flaggedReason); + } + + public void parseXML(Element element) { + this.user = element.getAttribute("user"); + this.name = element.getAttribute("name"); + this.showName = Boolean.valueOf(element.getAttribute("showName")); + this.token = element.getAttribute("token"); + this.email = element.getAttribute("email"); + this.hint = element.getAttribute("hint"); + this.website = element.getAttribute("website"); + this.connects = element.getAttribute("connects"); + this.bots = element.getAttribute("bots"); + this.posts = element.getAttribute("posts"); + this.messages = element.getAttribute("messages"); + this.forums = element.getAttribute("forums"); + this.channels = element.getAttribute("channels"); + this.avatars = element.getAttribute("avatars"); + this.scripts = element.getAttribute("scripts"); + this.graphics = element.getAttribute("graphics"); + this.domains = element.getAttribute("domains"); + this.joined = element.getAttribute("joined"); + this.lastConnect = element.getAttribute("lastConnect"); + this.type = element.getAttribute("type"); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + + Node node = element.getElementsByTagName("bio").item(0); + if (node != null) { + this.bio = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.bio != null) { + writer.write(""); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } - public void parseXML(Element element) { - this.user = element.getAttribute("user"); - this.name = element.getAttribute("name"); - this.showName = Boolean.valueOf(element.getAttribute("showName")); - this.token = element.getAttribute("token"); - this.email = element.getAttribute("email"); - this.hint = element.getAttribute("hint"); - this.website = element.getAttribute("website"); - this.connects = element.getAttribute("connects"); - this.bots = element.getAttribute("bots"); - this.posts = element.getAttribute("posts"); - this.messages = element.getAttribute("messages"); - this.forums = element.getAttribute("forums"); - this.channels = element.getAttribute("channels"); - this.avatars = element.getAttribute("avatars"); - this.scripts = element.getAttribute("scripts"); - this.graphics = element.getAttribute("graphics"); - this.domains = element.getAttribute("domains"); - this.joined = element.getAttribute("joined"); - this.lastConnect = element.getAttribute("lastConnect"); - this.type = element.getAttribute("type"); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - - Node node = element.getElementsByTagName("bio").item(0); - if (node != null) { - this.bio = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.bio != null) { - writer.write(""); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java index 01ee7fa..29fba15 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java @@ -25,50 +25,50 @@ import java.io.StringWriter; */ public class VoiceConfig extends Config { - public String voice; - public boolean nativeVoice; - public String language; - public String pitch; - public String speechRate; - public String mod; - - public void parseXML(Element element) { - super.parseXML(element); + public String voice; + public boolean nativeVoice; + public String language; + public String pitch; + public String speechRate; + public String mod; - this.voice = element.getAttribute("voice"); - this.nativeVoice = Boolean.valueOf(element.getAttribute("nativeVoice")); - this.language = element.getAttribute("language"); - this.pitch = element.getAttribute("pitch"); - this.speechRate = element.getAttribute("speechRate"); - this.mod = element.getAttribute("mod"); - } + public void parseXML(Element element) { + super.parseXML(element); - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java index 8de5fe4..561ed21 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java @@ -30,240 +30,240 @@ import java.util.Locale; */ public abstract class WebMediumConfig extends Config { - public String id; - public String name; - public boolean isAdmin; - public boolean isAdult; - public boolean isPrivate; - public boolean isHidden; - public String accessMode; - public boolean isFlagged; - public boolean isExternal; - public boolean isPaphus; - public boolean showAds = true; - public String forkAccessMode; - public String contentRating; - public String description; - public String details; - public String disclaimer; - public String website; - public String subdomain; - public String tags; - public String categories; - public String flaggedReason; - public String creator; - public String creationDate; - public String lastConnectedUser; - public String license; - public String avatar; - public String script; - public String graphic; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public String connects; - public String dailyConnects; - public String weeklyConnects; - public String monthlyConnects; - - public abstract String toXML(); - - public abstract String getType(); - - public abstract WebMediumConfig credentials(); - - public String stats() { - return ""; - } - - public boolean equals(Object object) { - if (object instanceof WebMediumConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((WebMediumConfig)object).id); - } - return false; - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayDate(date); - } catch (Exception exception) { - return creationDate; - } - } - - public long getToken() { - long token = 0; - if ((this.token != null) && (this.token.equals(""))) { - token = Long.valueOf(this.token); - } - return token; - } + public String id; + public String name; + public boolean isAdmin; + public boolean isAdult; + public boolean isPrivate; + public boolean isHidden; + public String accessMode; + public boolean isFlagged; + public boolean isExternal; + public boolean isPaphus; + public boolean showAds = true; + public String forkAccessMode; + public String contentRating; + public String description; + public String details; + public String disclaimer; + public String website; + public String subdomain; + public String tags; + public String categories; + public String flaggedReason; + public String creator; + public String creationDate; + public String lastConnectedUser; + public String license; + public String avatar; + public String script; + public String graphic; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public String connects; + public String dailyConnects; + public String weeklyConnects; + public String monthlyConnects; - public void writeXML(StringWriter writer) { - writeCredentials(writer); - if (this.id != null) { - writer.write(" id=\"" + this.id + "\""); - } - if (this.name != null) { - writer.write(" name=\"" + this.name + "\""); - } - if (this.isPrivate) { - writer.write(" isPrivate=\"true\""); - } - if (this.isHidden) { - writer.write(" isHidden=\"true\""); - } - if (this.accessMode != null && !this.accessMode.equals("")) { - writer.write(" accessMode=\"" + this.accessMode + "\""); - } - if (this.contentRating != null && !this.contentRating.equals("")) { - writer.write(" contentRating=\"" + this.contentRating + "\""); - } - if (this.forkAccessMode != null && !this.forkAccessMode.equals("")) { - writer.write(" forkAccessMode=\"" + this.forkAccessMode + "\""); - } + public abstract String toXML(); - if (this.stars != null && !this.stars.equals("")) { - writer.write(" stars=\"" + this.stars + "\""); - } - if (this.isAdult) { - writer.write(" isAdult=\"true\""); - } - if (this.isFlagged) { - writer.write(" isFlagged=\"true\""); - } - if (this.isExternal) { - writer.write(" isExternal=\"true\""); - } - if (this.showAds) { - writer.write(" showAds=\"true\""); - } - writer.write(">"); - if (this.description != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.description)); - writer.write(""); - } - if (this.details != null) { - writer.write("
"); - writer.write(Utils.escapeHTML(this.details)); - writer.write("
"); - } - if (this.disclaimer != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.disclaimer)); - writer.write(""); - } - if (this.categories != null) { - writer.write(""); - writer.write(this.categories); - writer.write(""); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.license != null) { - writer.write(""); - writer.write(this.license); - writer.write(""); - } - if (this.website != null) { - writer.write(""); - writer.write(this.website); - writer.write(""); - } - if (this.subdomain != null) { - writer.write(""); - writer.write(this.subdomain); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.name = element.getAttribute("name"); - this.creationDate = element.getAttribute("creationDate"); - this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate")); - this.isHidden = Boolean.valueOf(element.getAttribute("isHidden")); - this.accessMode = element.getAttribute("accessMode"); - this.contentRating = element.getAttribute("contentRating"); - this.forkAccessMode = element.getAttribute("forkAccessMode"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.isAdult = Boolean.valueOf(element.getAttribute("isAdult")); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isExternal = Boolean.valueOf(element.getAttribute("isExternal")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - this.connects = element.getAttribute("connects"); - this.dailyConnects = element.getAttribute("dailyConnects"); - this.weeklyConnects = element.getAttribute("weeklyConnects"); - this.showAds = Boolean.valueOf(element.getAttribute("showAds")); - this.monthlyConnects = element.getAttribute("monthlyConnects"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("description").item(0); - if (node != null) { - this.description = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("disclaimer").item(0); - if (node != null) { - this.disclaimer = node.getTextContent(); - } - node = element.getElementsByTagName("categories").item(0); - if (node != null) { - this.categories = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("lastConnectedUser").item(0); - if (node != null) { - this.lastConnectedUser = node.getTextContent(); - } - node = element.getElementsByTagName("license").item(0); - if (node != null) { - this.license = node.getTextContent(); - } - node = element.getElementsByTagName("website").item(0); - if (node != null) { - this.website = node.getTextContent(); - } - node = element.getElementsByTagName("subdomain").item(0); - if (node != null) { - this.subdomain = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - } + public abstract String getType(); + + public abstract WebMediumConfig credentials(); + + public String stats() { + return ""; + } + + public boolean equals(Object object) { + if (object instanceof WebMediumConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((WebMediumConfig) object).id); + } + return false; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayDate(date); + } catch (Exception exception) { + return creationDate; + } + } + + public long getToken() { + long token = 0; + if ((this.token != null) && (this.token.equals(""))) { + token = Long.valueOf(this.token); + } + return token; + } + + public void writeXML(StringWriter writer) { + writeCredentials(writer); + if (this.id != null) { + writer.write(" id=\"" + this.id + "\""); + } + if (this.name != null) { + writer.write(" name=\"" + this.name + "\""); + } + if (this.isPrivate) { + writer.write(" isPrivate=\"true\""); + } + if (this.isHidden) { + writer.write(" isHidden=\"true\""); + } + if (this.accessMode != null && !this.accessMode.equals("")) { + writer.write(" accessMode=\"" + this.accessMode + "\""); + } + if (this.contentRating != null && !this.contentRating.equals("")) { + writer.write(" contentRating=\"" + this.contentRating + "\""); + } + if (this.forkAccessMode != null && !this.forkAccessMode.equals("")) { + writer.write(" forkAccessMode=\"" + this.forkAccessMode + "\""); + } + + if (this.stars != null && !this.stars.equals("")) { + writer.write(" stars=\"" + this.stars + "\""); + } + if (this.isAdult) { + writer.write(" isAdult=\"true\""); + } + if (this.isFlagged) { + writer.write(" isFlagged=\"true\""); + } + if (this.isExternal) { + writer.write(" isExternal=\"true\""); + } + if (this.showAds) { + writer.write(" showAds=\"true\""); + } + writer.write(">"); + if (this.description != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.description)); + writer.write(""); + } + if (this.details != null) { + writer.write("
"); + writer.write(Utils.escapeHTML(this.details)); + writer.write("
"); + } + if (this.disclaimer != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.disclaimer)); + writer.write(""); + } + if (this.categories != null) { + writer.write(""); + writer.write(this.categories); + writer.write(""); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.license != null) { + writer.write(""); + writer.write(this.license); + writer.write(""); + } + if (this.website != null) { + writer.write(""); + writer.write(this.website); + writer.write(""); + } + if (this.subdomain != null) { + writer.write(""); + writer.write(this.subdomain); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.name = element.getAttribute("name"); + this.creationDate = element.getAttribute("creationDate"); + this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate")); + this.isHidden = Boolean.valueOf(element.getAttribute("isHidden")); + this.accessMode = element.getAttribute("accessMode"); + this.contentRating = element.getAttribute("contentRating"); + this.forkAccessMode = element.getAttribute("forkAccessMode"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.isAdult = Boolean.valueOf(element.getAttribute("isAdult")); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isExternal = Boolean.valueOf(element.getAttribute("isExternal")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + this.connects = element.getAttribute("connects"); + this.dailyConnects = element.getAttribute("dailyConnects"); + this.weeklyConnects = element.getAttribute("weeklyConnects"); + this.showAds = Boolean.valueOf(element.getAttribute("showAds")); + this.monthlyConnects = element.getAttribute("monthlyConnects"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("description").item(0); + if (node != null) { + this.description = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("disclaimer").item(0); + if (node != null) { + this.disclaimer = node.getTextContent(); + } + node = element.getElementsByTagName("categories").item(0); + if (node != null) { + this.categories = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("lastConnectedUser").item(0); + if (node != null) { + this.lastConnectedUser = node.getTextContent(); + } + node = element.getElementsByTagName("license").item(0); + if (node != null) { + this.license = node.getTextContent(); + } + node = element.getElementsByTagName("website").item(0); + if (node != null) { + this.website = node.getTextContent(); + } + node = element.getElementsByTagName("subdomain").item(0); + if (node != null) { + this.subdomain = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java index 1b2e369..83e57f1 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java @@ -23,14 +23,14 @@ package org.botlibre.sdk; * http://www.botlibre.com */ public class BOTlibreCredentials extends Credentials { - public static final String DOMAIN = "www.botlibre.com"; - public static final String APP = ""; - public static final String PATH = "/rest/api"; + public static final String DOMAIN = "www.botlibre.com"; + public static final String APP = ""; + public static final String PATH = "/rest/api"; - public BOTlibreCredentials(String applicationId) { - this.host = DOMAIN; - this.app = APP; - this.url = "https://" + DOMAIN + APP + PATH; - this.applicationId = applicationId; - } + public BOTlibreCredentials(String applicationId) { + this.host = DOMAIN; + this.app = APP; + this.url = "https://" + DOMAIN + APP + PATH; + this.applicationId = applicationId; + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/Credentials.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/Credentials.java index ace1a72..9aa2e18 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/Credentials.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/Credentials.java @@ -24,71 +24,71 @@ package org.botlibre.sdk; * You can obtain your application id from your user details page on the hosting website. */ public class Credentials { - public String host = ""; - public String app = ""; - public String url = ""; - /** - * Your application's unique identifier. - * You can obtain your application id from your user details page on the hosting website. - */ - public String applicationId = ""; + public String host = ""; + public String app = ""; + public String url = ""; + /** + * Your application's unique identifier. + * You can obtain your application id from your user details page on the hosting website. + */ + public String applicationId = ""; - public Credentials() { - } + public Credentials() { + } - /** - * Creates a new credentials for the service host url, and the application id. - */ - public Credentials(String url, String applicationId) { - this.url = url; - this.applicationId = applicationId; - } + /** + * Creates a new credentials for the service host url, and the application id. + */ + public Credentials(String url, String applicationId) { + this.url = url; + this.applicationId = applicationId; + } - public String getUrl() { - return url; - } - - /** - * Sets the hosted service server url, i.e. http://www.paphuslivechat.com - * - * @param url String - */ - public void setUrl(String url) { - this.url = url; - } + public String getUrl() { + return url; + } - public String getHost() { - return host; - } + /** + * Sets the hosted service server url, i.e. http://www.paphuslivechat.com + * + * @param url String + */ + public void setUrl(String url) { + this.url = url; + } - /** - * Sets the server host name, i.e. www.paphuslivechat.com - * - * @param host String - */ - public void setHost(String host) { - this.host = host; - } + public String getHost() { + return host; + } - public String getApp() { - return app; - } + /** + * Sets the server host name, i.e. www.paphuslivechat.com + * + * @param host String + */ + public void setHost(String host) { + this.host = host; + } - /** - * Sets an app url postfix, this is normally not required, i.e. "". - * - * @param app String - */ - public void setApp(String app) { - this.app = app; - } + public String getApp() { + return app; + } - /** - * Returns your application's unique identifier. - * - * @return String - */ - public String getApplicationId() { - return applicationId; - } + /** + * Sets an app url postfix, this is normally not required, i.e. "". + * + * @param app String + */ + public void setApp(String app) { + this.app = app; + } + + /** + * Returns your application's unique identifier. + * + * @return String + */ + public String getApplicationId() { + return applicationId; + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/SDKException.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/SDKException.java index dc730b7..2bf3c59 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/SDKException.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/SDKException.java @@ -25,19 +25,19 @@ package org.botlibre.sdk; */ public class SDKException extends RuntimeException { - public SDKException(Exception exception) { - super(exception.getMessage(), exception); - } - - public SDKException(String message) { - super(message); - } - - public SDKException(String message, Exception exception) { - super(message, exception); - } - - public static SDKException parseFailure(Exception exception) { - throw new SDKException("parse failure", exception); - } + public SDKException(Exception exception) { + super(exception.getMessage(), exception); + } + + public SDKException(String message) { + super(message); + } + + public SDKException(String message, Exception exception) { + super(message, exception); + } + + public static SDKException parseFailure(Exception exception) { + throw new SDKException("parse failure", exception); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java index a113dbe..ddeeaac 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/BotSearchAbility.java @@ -26,43 +26,44 @@ import ohos.agp.components.Text; * Browse Ability for searching for a bot. */ public class BotSearchAbility extends SearchAbility implements SelectListener { - private int type = 0; - private Text sortSpin; - private Text restrictSpin; - private String[] sortSpinStr = new String[]{ - "connects", - "connects today", - "connects this week", - "connects this month", - "last connect", - "name", - "date", - "size", - "rank", - "wins", - "losses", - "thumbs up", - "thumbs down", - "stars" - }; - private String[] restrictSpinStr = new String[]{ - "", - "forkable", - "has website", - "has subdomain", - "external link", - "Platinum", - "Gold", - "Bronze" - }; - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void onStart(Intent intent) { - super.onStart(intent); + private int type = 0; + private Text sortSpin; + private Text restrictSpin; + private String[] sortSpinStr = new String[]{ + "connects", + "connects today", + "connects this week", + "connects this month", + "last connect", + "name", + "date", + "size", + "rank", + "wins", + "losses", + "thumbs up", + "thumbs down", + "stars" + }; + private String[] restrictSpinStr = new String[]{ + "", + "forkable", + "has website", + "has subdomain", + "external link", + "Platinum", + "Gold", + "Bronze" + }; + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public void onStart(Intent intent) { + super.onStart(intent); // Checkbox checkbox = (Checkbox)findComponentById(ResourceTable.Id_imagesCheckBox); // checkbox.setChecked(MainAbility.showImages); - + // sortSpin = (Text)findComponentById(ResourceTable.Id_sortSpin); // sortSpin.setClickedListener(new Component.ClickedListener() { // @Override @@ -80,9 +81,9 @@ public class BotSearchAbility extends SearchAbility implements SelectListener { // SearchDialogBuilder.with(BotSearchAbility.this,restrictSpinStr).setSelectInterface(BotSearchAbility.this); // } // }); - } - - public String getType() { - return "Bot"; - } + } + + public String getType() { + return "Bot"; + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java deleted file mode 100644 index 6482acb..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java +++ /dev/null @@ -1,33 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability; - -/** - * A convenience enum of different emotional states. - */ - -public enum EmotionalState { - NONE, - LOVE, LIKE, DISLIKE, HATE, - RAGE, ANGER, CALM, SERENE, - ECSTATIC, HAPPY, SAD, CRYING, - PANIC, AFRAID, CONFIDENT, COURAGEOUS, - SURPRISE, BORED, - LAUGHTER, SERIOUS; -} diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index a4d18ed..b8c488b 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -26,20 +26,20 @@ import ohos.aafwk.content.Operation; * Generic Ability for common behavior. */ public abstract class LibreAbility extends Ability { - /** - * 启动ability - * - * @param ability Ability - * @param name String - */ - public void startOpenAbility(Ability ability,String name){ - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - startAbility(intent); - } + /** + * 启动ability + * + * @param ability Ability + * @param name String + */ + public void startOpenAbility(Ability ability, String name) { + Intent intent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(ability.getBundleName()) + .withAbilityName(name) + .build(); + intent.setOperation(operation); + startAbility(intent); + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java index 543cd67..10f02dc 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java @@ -26,26 +26,26 @@ import ohos.aafwk.content.Intent; import org.botlibre.sdk.config.OfflineTemplateConfig; public class ListTemplateView extends Ability { - final static String listOfBots [] = {"Empty" , "Basic", "Personal Assistance"}; - final static int imagesId [] = {ResourceTable.Media_bot, ResourceTable.Media_bot , ResourceTable.Media_bot}; - final static String listOfDec [] = {"A completely empty template loaded with no knowledge or scripts.", - "A basic bot template with only responses to common greetings and farewells (hello, goodbye, etc.), and the default bootstrap Self language scripts that understand basic language, 'what is' and 'where is' questions, names, dates, math, and topical questions.", - "Template for a Virtual Assistant. This template has command scripts for performing common tasks on such as opening apps, scheduling appointments, and send email."}; + final static String listOfBots[] = {"Empty", "Basic", "Personal Assistance"}; + final static int imagesId[] = {ResourceTable.Media_bot, ResourceTable.Media_bot, ResourceTable.Media_bot}; + final static String listOfDec[] = {"A completely empty template loaded with no knowledge or scripts.", + "A basic bot template with only responses to common greetings and farewells (hello, goodbye, etc.), and the default bootstrap Self language scripts that understand basic language, 'what is' and 'where is' questions, names, dates, math, and topical questions.", + "Template for a Virtual Assistant. This template has command scripts for performing common tasks on such as opening apps, scheduling appointments, and send email."}; - @SuppressWarnings("unchecked") - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_list_view); - } + @SuppressWarnings("unchecked") + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_list_view); + } - public static List retriveTemplates(){ - List items = new ArrayList(); - for (int i = 0; i < listOfBots.length; i++) { - OfflineTemplateConfig item = new OfflineTemplateConfig(imagesId[i],listOfBots[i],listOfDec[i],""+i,i); - items.add(item); - } - return items; - } + public static List retriveTemplates() { + List items = new ArrayList(); + for (int i = 0; i < listOfBots.length; i++) { + OfflineTemplateConfig item = new OfflineTemplateConfig(imagesId[i], listOfBots[i], listOfDec[i], "" + i, i); + items.add(item); + } + return items; + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java index 220cb17..80fac96 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java @@ -26,40 +26,41 @@ import ohos.aafwk.ability.Ability; public class HttpChatAction extends HttpAction { - ChatConfig config; - public HttpChatAction(Ability ability, ChatConfig config) { - super(ability); - this.config = config; - } + ChatConfig config; - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().chat(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPreExecute() { - if (!this.config.disconnect) { - super.onPreExecute(); - } - } + public HttpChatAction(Ability ability, ChatConfig config) { + super(ability); + this.config = config; + } - @Override - protected void onPostExecute(String xml) { - if (this.config.disconnect) { - return; - } - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.errorInfo(1,this.exception.getMessage(), this.exception, this.ability); - return; - } - try { + @Override + protected String doInBackground(Void... params) { + try { + MainAbility.getConnection().chat(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } + + @Override + protected void onPreExecute() { + if (!this.config.disconnect) { + super.onPreExecute(); + } + } + + @Override + protected void onPostExecute(String xml) { + if (this.config.disconnect) { + return; + } + super.onPostExecute(xml); + if (this.exception != null) { + MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); + return; + } + try { // MainAbility.conversation = this.response.conversation; // final ChatAbility Ability = (ChatAbility)this.ability; // @@ -153,10 +154,10 @@ public class HttpChatAction extends HttpAction { // } // // Ability.response(this.response); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } + } catch (Exception error) { + this.exception = error; + MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + return; + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java index 55b0902..d38c0f5 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java @@ -19,42 +19,41 @@ package org.botlibre.sdk.ability.actions; - import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.ability.Ability; import ohos.app.Context; public class HttpCreateUserAction extends HttpUIResultAction { - UserConfig config; - - public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { - super(ability); - this.config = config; - doInBackground(); - } - -// @Override - protected void doInBackground() { - try { - this.config = MainAbility.getConnection().create(ability,this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - - if (this.exception != null) { - return; - } - try { - MainAbility.setUser(this.config); - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - removeDialog(); - return; - } - - } + UserConfig config; + + public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { + super(ability); + this.config = config; + doInBackground(); + } + + // @Override + protected void doInBackground() { + try { + this.config = MainAbility.getConnection().create(ability, this.config); + } catch (Exception exception) { + this.exception = exception; + removeDialog(); + return; + } + + if (this.exception != null) { + return; + } + try { + MainAbility.setUser(this.config); + this.ability.terminateAbility(); + } catch (Exception error) { + this.exception = error; + removeDialog(); + return; + } + + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java index f3e80d6..ab2e355 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java @@ -21,36 +21,37 @@ package org.botlibre.sdk.ability.actions; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.config.AvatarConfig; import ohos.aafwk.ability.Ability; + public class HttpFetchChatAvatarAction extends HttpUIAction { - AvatarConfig config; + AvatarConfig config; + + public HttpFetchChatAvatarAction(Ability ability, AvatarConfig config) { + super(ability); + this.config = config; + } - public HttpFetchChatAvatarAction(Ability ability, AvatarConfig config) { - super(ability); - this.config = config; - } + @Override + protected String doInBackground(Void... params) { + try { + this.config = MainAbility.getConnection().fetch(this.config); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.getConnection().fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + public void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + try { + } catch (Exception error) { + this.exception = error; + MainAbility.error(this.exception.getMessage(), this.exception, this.ability); + return; + } + } - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java index 816ff61..a71e82f 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java @@ -27,29 +27,29 @@ import javax.swing.text.html.ListView; import java.util.List; public class HttpGetTemplatesAction extends HttpAction { - List templates; - - public HttpGetTemplatesAction(Ability Ability) { - super(Ability); - - } - - @Override - protected String doInBackground(Void... params) { - try { - this.templates = MainAbility.getConnection().getTemplates(); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - public void postExecute(String xml) { - if (this.exception != null) { - return; - } - - MainAbility.setTemplates(this.templates); - - } + List templates; + + public HttpGetTemplatesAction(Ability Ability) { + super(Ability); + + } + + @Override + protected String doInBackground(Void... params) { + try { + this.templates = MainAbility.getConnection().getTemplates(); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } + + public void postExecute(String xml) { + if (this.exception != null) { + return; + } + + MainAbility.setTemplates(this.templates); + + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java index a8a52bb..43ef52f 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java @@ -32,41 +32,41 @@ import ohos.agp.window.service.DisplayManager; import java.util.Optional; public abstract class HttpUIAction extends HttpAction { - protected CommonDialog dialog; + protected CommonDialog dialog; - public HttpUIAction(Ability Ability) { - super(Ability); - } + public HttpUIAction(Ability Ability) { + super(Ability); + } - // 加载 - public void loadingDialog(){ - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } + // 加载 + public void loadingDialog() { + try { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); + DisplayAttributes displayAttributes = display.get().getAttributes(); + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). + parse(ResourceTable.Layout_loading_dialog, + null, false); + this.dialog = new CommonDialog(this.ability); + this.dialog.setContentCustomComponent(layout); + this.dialog.setAutoClosable(false); + this.dialog.setSize(displayAttributes.width - 100, 150); + this.dialog.show(); + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); + } + } - public void removeDialog(){ - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1,this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } + public void removeDialog() { + try { + if (this.dialog != null) { + this.dialog.destroy(); + } + if (this.exception != null) { + MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); + } + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java index c952ff7..b79ac22 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java @@ -33,45 +33,41 @@ import ohos.agp.window.service.DisplayManager; import java.util.Optional; public abstract class HttpUIResultAction extends HttpResultAction { - protected CommonDialog dialog; + protected CommonDialog dialog; - public HttpUIResultAction(Ability Ability) { - super(Ability); - } + public HttpUIResultAction(Ability Ability) { + super(Ability); + } - // 加载 - public void loadingDialog(){ - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100,150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } + // 加载 + public void loadingDialog() { + try { + Optional + display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); + DisplayAttributes displayAttributes = display.get().getAttributes(); + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). + parse(ResourceTable.Layout_loading_dialog, + null, false); + this.dialog = new CommonDialog(this.ability); + this.dialog.setContentCustomComponent(layout); + this.dialog.setAutoClosable(false); + this.dialog.setSize(displayAttributes.width - 100, 150); + this.dialog.show(); + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); + } + } - public void removeDialog(){ - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { -// if(!exception.toString().equals("403")) { -// MainAbility.error(this.exception.getMessage(), this.exception, this.ability); -// } else { - MainAbility.errorInfo(1,ResUtils.getString(ability,ResourceTable.String_exception), this.exception, this.ability); -// } - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } + public void removeDialog() { + try { + if (this.dialog != null) { + this.dialog.destroy(); + } + if (this.exception != null) { + MainAbility.errorInfo(1, ResUtils.getString(ability, ResourceTable.String_exception), this.exception, this.ability); + } + } catch (Exception exception) { + LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java index 89f91d0..2e498d3 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/avatar/AvatarSelection.java @@ -31,29 +31,29 @@ import ohos.data.preferences.Preferences; import java.util.ArrayList; /** - * used for selecting an offline avatar. + * used for selecting an offline avatar. */ public class AvatarSelection extends Ability { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_ability_list_view); - final int [] imges = {}; - final String [] names = {}; - ((Text) findComponentById(ResourceTable.Id_theTitle)).setText("Select Avatar"); - ArrayList items = new ArrayList(); - for (int i = 0; i < names.length; i++) { - items.add(new OfflineTemplateConfig(imges[i],names[i],null,null)); - } - - } - - public static void saveSelectedAvatar(String nameOfAvatar) { - MainAbility.setNameOfAvatar(nameOfAvatar); - Preferences cookies = PreferencesUtils.getPreferences(MainAbility.getCurrent()); - cookies.putString("nameOfAvatar", nameOfAvatar); - cookies.flushSync(); - } + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_list_view); + final int[] imges = {}; + final String[] names = {}; + ((Text) findComponentById(ResourceTable.Id_theTitle)).setText("Select Avatar"); + ArrayList items = new ArrayList(); + for (int i = 0; i < names.length; i++) { + items.add(new OfflineTemplateConfig(imges[i], names[i], null, null)); + } + + } + + public static void saveSelectedAvatar(String nameOfAvatar) { + MainAbility.setNameOfAvatar(nameOfAvatar); + Preferences cookies = PreferencesUtils.getPreferences(MainAbility.getCurrent()); + cookies.putString("nameOfAvatar", nameOfAvatar); + cookies.flushSync(); + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java index 8e66c9b..f7f9615 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java @@ -23,10 +23,10 @@ package org.botlibre.sdk.ability.listener; * This gives asynchronous notification when a channel receives a message, or notice. */ public interface LanguageListener { - /** - * A user message was received from the channel. - * - * @param select String - */ - void selectLanguageItem(String select); + /** + * A user message was received from the channel. + * + * @param select String + */ + void selectLanguageItem(String select); } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java index 12704d2..c97572a 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/listener/SelectListener.java @@ -23,10 +23,10 @@ package org.botlibre.sdk.ability.listener; * This gives asynchronous notification when a channel receives a message, or notice. */ public interface SelectListener { - /** - * A user message was received from the channel. - * - * @param select String - */ - void selectItem(String select); + /** + * A user message was received from the channel. + * + * @param select String + */ + void selectItem(String select); } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java index 7d0c9ee..f6a3c42 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/ChatWarConfig.java @@ -8,37 +8,37 @@ import java.io.StringWriter; * DTO for XML chat war config. */ public class ChatWarConfig extends Config { - public String winner; - public String looser; - public String topic; - public String secret; - - public ChatWarConfig() { - - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String winner; + public String looser; + public String topic; + public String secret; + + public ChatWarConfig() { + + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java index 11be68b..2f0b255 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java @@ -6,32 +6,32 @@ import org.botlibre.sdk.config.InstanceConfig; import ohos.aafwk.ability.Ability; public class HttpChatWarAction extends HttpUIAction { - ChatWarConfig config; - InstanceConfig instance; + ChatWarConfig config; + InstanceConfig instance; - public HttpChatWarAction(Ability ability, ChatWarConfig config) { - super(ability); - this.config = config; - } + public HttpChatWarAction(Ability ability, ChatWarConfig config) { + super(ability); + this.config = config; + } - @Override - protected String doInBackground(Void... params) { - try { - InstanceConfig instance = new InstanceConfig(); - this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } + @Override + protected String doInBackground(Void... params) { + try { + InstanceConfig instance = new InstanceConfig(); + this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); + } catch (Exception exception) { + this.exception = exception; + } + return ""; + } + + @Override + protected void onPostExecute(String xml) { + super.onPostExecute(xml); + if (this.exception != null) { + return; + } + MainAbility.setInstance(this.instance); + } - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setInstance(this.instance); - } - } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java index 41dbaed..fd38b28 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java @@ -32,545 +32,547 @@ import org.w3c.dom.Element; * DTO for XML avatar config. */ public class AvatarConfig extends WebMediumConfig { - public Map mediaConfig; - private String avatarFormat; - private boolean avatarHD; - public String background; - public String icon; - - public String getType() { - return "avatar"; - } - public AvatarConfig(){ - mediaConfig = new HashMap(); - } + public Map mediaConfig; + private String avatarFormat; + private boolean avatarHD; + public String background; + public String icon; + + public String getType() { + return "avatar"; + } + + public AvatarConfig() { + mediaConfig = new HashMap(); + } + + /** + * chatReply + * + * @param chat ChatResponse + * @return ChatResponse + */ + public ChatResponse chatReply(ChatResponse chat) { + String emotion = MicroConnection.getBot().mood().currentEmotionalState().name(); + String action = MicroConnection.getBot().avatar().getAction(); + String pose = MicroConnection.getBot().avatar().getPose(); + if (this.getBackground() != null) { + String background = this.getBackground(); + chat.avatarBackground = background; + } + List matching = null; + + // Audio + if (action != null) { + matching = this.getAudio(action, pose); + if (!matching.isEmpty()) { + AvatarMedia media = Utils.random(matching); + String[] array = media.media.split("\\."); + chat.avatarActionAudio = media.mediaId + "." + array[1]; + chat.avatarActionAudioType = media.getType(); + } + } + matching = this.getAudio("", pose); + if (!matching.isEmpty()) { + AvatarMedia media = Utils.random(matching); + String[] array = media.media.split("\\."); + chat.avatarAudio = media.mediaId + "." + array[1]; + chat.avatarAudioType = media.getType(); + } + // Image/video + if (action != null) { + matching = this.getMedia(emotion, action, pose, ""); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatarAction = media.mediaId + "." + array[1]; + } + } + matching = this.getMedia(emotion, "", pose, ""); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatar = media.mediaId + "." + array[1]; + chat.avatar2 = null; + chat.avatar3 = null; + chat.avatar4 = null; + chat.avatar5 = null; + if (matching.size() > 1) { + AvatarMedia media2 = randomMatch(matching); + AvatarMedia media3 = randomMatch(matching); + AvatarMedia media4 = randomMatch(matching); + AvatarMedia media5 = randomMatch(matching); + if (media != media2 || media != media3 || media != media4 || media != media5) { + array = media2.media.split("\\."); + chat.avatar2 = media2.mediaId + "." + array[1]; + array = media3.media.split("\\."); + chat.avatar3 = media3.mediaId + "." + array[1]; + array = media4.media.split("\\."); + chat.avatar4 = media4.mediaId + "." + array[1]; + array = media5.media.split("\\."); + chat.avatar5 = media5.mediaId + "." + array[1]; + } + } + chat.avatarType = media.getType(); + } + matching = this.getMedia(emotion, "", pose, "talking"); + if (!matching.isEmpty()) { + AvatarMedia media = randomMatch(matching); + String[] array = media.media.split("\\."); + chat.avatarTalk = media.mediaId + "." + array[1]; + chat.avatarTalkType = media.getType(); + } + return chat; + } + + /** + * credentials + * + * @return WebMediumConfig + */ + public WebMediumConfig credentials() { + AvatarConfig config = new AvatarConfig(); + config.id = this.id; + return config; + } - /** - * chatReply - * - * @param chat ChatResponse - * @return ChatResponse - * */ - public ChatResponse chatReply(ChatResponse chat) { - String emotion = MicroConnection.getBot().mood().currentEmotionalState().name(); - String action = MicroConnection.getBot().avatar().getAction(); - String pose = MicroConnection.getBot().avatar().getPose(); - if (this.getBackground() != null) { - String background = this.getBackground(); - chat.avatarBackground = background; - } - List matching = null; - - // Audio - if (action != null) { - matching = this.getAudio(action, pose); - if (!matching.isEmpty()) { - AvatarMedia media = Utils.random(matching); - String [] array = media.media.split("\\."); - chat.avatarActionAudio = media.mediaId + "." + array[1]; - chat.avatarActionAudioType = media.getType(); - } - } - matching = this.getAudio("", pose); - if (!matching.isEmpty()) { - AvatarMedia media = Utils.random(matching); - String [] array = media.media.split("\\."); - chat.avatarAudio = media.mediaId + "." + array[1]; - chat.avatarAudioType = media.getType(); - } - // Image/video - if (action != null) { - matching = this.getMedia(emotion, action, pose, ""); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatarAction = media.mediaId+"."+array[1]; - } - } - matching = this.getMedia(emotion, "", pose, ""); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatar = media.mediaId+"."+array[1]; - chat.avatar2 = null; - chat.avatar3 = null; - chat.avatar4 = null; - chat.avatar5 = null; - if (matching.size() > 1) { - AvatarMedia media2 = randomMatch(matching); - AvatarMedia media3 = randomMatch(matching); - AvatarMedia media4 = randomMatch(matching); - AvatarMedia media5 = randomMatch(matching); - if (media != media2 || media != media3 || media != media4 || media != media5) { - array = media2.media.split("\\."); - chat.avatar2 = media2.mediaId+"."+array[1]; - array = media3.media.split("\\."); - chat.avatar3 = media3.mediaId+"."+array[1]; - array = media4.media.split("\\."); - chat.avatar4 = media4.mediaId+"."+array[1]; - array = media5.media.split("\\."); - chat.avatar5 = media5.mediaId+"."+array[1]; - } - } - chat.avatarType = media.getType(); - } - matching = this.getMedia(emotion, "", pose, "talking"); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String [] array = media.media.split("\\."); - chat.avatarTalk = media.mediaId +"." +array[1]; - chat.avatarTalkType = media.getType(); - } - return chat; - } /** - * credentials - * - * @return WebMediumConfig - * */ - public WebMediumConfig credentials() { - AvatarConfig config = new AvatarConfig(); - config.id = this.id; - return config; - } + * toXML + * + * @return String + */ + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } - /** - * toXML - * - * @return String - * */ - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + /** + * parseXML + * + * @param element Element + */ + public void parseXML(Element element) { + super.parseXML(element); + } + + /** + * Find any media that match the emotion, action, and pose, or the best matches. + * + * @param emotion String + * @param action String + * @param pose String + * @param pose2 String + * @return List + */ + public List getMedia(String emotion, String action, String pose, String pose2) { + if (emotion == null || emotion.isEmpty()) { + emotion = "NONE"; + } else { + emotion = emotion.toUpperCase(); + } + if (action == null) { + action = ""; + } + if (pose == null) { + pose = ""; + } + if (pose2 == null) { + pose2 = ""; + } + boolean talking = pose2.equals("talking"); + List matches = new ArrayList(); + boolean none = emotion.equals("NONE"); - /** - * parseXML - * - * @param element Element - * */ - public void parseXML(Element element) { - super.parseXML(element); - } - - /** - * Find any media that match the emotion, action, and pose, or the best matches. - * - * @param emotion String - * @param action String - * @param pose String - * @param pose2 String - * @return List - */ - public List getMedia(String emotion, String action, String pose, String pose2) { - if (emotion == null || emotion.isEmpty()) { - emotion = "NONE"; - } else { - emotion = emotion.toUpperCase(); - } - if (action == null) { - action = ""; - } - if (pose == null) { - pose = ""; - } - if (pose2 == null) { - pose2 = ""; - } - boolean talking = pose2.equals("talking"); - List matches = new ArrayList(); - boolean none = emotion.equals("NONE"); - - boolean[][] matching = new boolean[this.mediaConfig.size()][4]; - int index = 0; - // All match. - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean emotionMatch = media.getEmotions().contains(emotion) || (none && media.getEmotions().isEmpty()); - if (emotionMatch && emotion.equals("RAGE") && media.getEmotions().contains("COURAGE")) { - // Both contain "rage". - emotionMatch = false; - } - if (emotionMatch && emotion.equals("LIKE") && media.getEmotions().contains("DISLIKE")) { - // Both contain "like". - emotionMatch = false; - } - boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); - boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); - boolean pose2Match = (!pose2.isEmpty() && media.getPoses().contains(pose2)) || pose2.isEmpty(); - if (!pose2Match && pose2.equals("talking")) { - pose2Match = media.getTalking(); - } else if (media.getTalking() && !talking) { - pose2Match = false; - } - matching[index][0] = emotionMatch; - matching[index][1] = actionMatch; - matching[index][2] = poseMatch; - matching[index][3] = pose2Match; - index++; - if (emotionMatch && actionMatch && poseMatch && pose2Match) { - matches.add(media); - } - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 and pose matches. - if (!pose2.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean poseMatch = matching[index][2]; - boolean pose2Match = matching[index][3]; - if (poseMatch && pose2Match) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 and emotion matches. - index = 0; - for (AvatarMedia media :this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - boolean pose2Match = matching[index][3]; - if (emotionMatch && pose2Match) { - if (!media.getPoses().isEmpty()) { - index++; - continue; - } - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean pose2Match = matching[index][3]; - if (pose2Match) { - if (!media.getPoses().isEmpty()) { - index++; - continue; - } - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose2 any matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - boolean pose2Match = matching[index][3]; - if (pose2Match) { - matches.add(media); - } - index++; - } - // For pose2, the pose is required (i.e. talking). - return matches; - } - // Action and pose matches. - if (!action.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean actionMatch = matching[index][1]; - boolean poseMatch = matching[index][2]; - if (actionMatch && poseMatch) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Action matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean actionMatch = matching[index][1]; - if (actionMatch - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - // For actions, the action is required. - return matches; - } - // Pose and emotion matches. - if (!pose.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - boolean poseMatch = matching[index][2]; - if (poseMatch && emotionMatch && media.getActions().isEmpty()) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Pose matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean poseMatch = matching[index][2]; - if (poseMatch && media.getActions().isEmpty() - && (media.getEmotions().isEmpty() || media.getEmotions().contains("NONE"))) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - } - // Emotion matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - boolean emotionMatch = matching[index][0]; - if (emotionMatch - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - // Default matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (media.isAudio()) { - index++; - continue; - } - if (!talking && media.getTalking()) { - index++; - continue; - } - if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - return matches; - } - - /** - * Find an audio media that matches the action or pose. - * - * @param action String - * @param pose String - * @return List - */ - public List getAudio(String action, String pose) { - if (action == null) { - action = ""; - } - if (pose == null) { - pose = ""; - } - List matches = new ArrayList(); - - boolean[][] matching = new boolean[this.mediaConfig.size()][2]; - int index = 0; - // All match. - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); - boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); - matching[index][0] = actionMatch; - matching[index][1] = poseMatch; - index++; - if (actionMatch && poseMatch) { - matches.add(media); - } - } - if (!matches.isEmpty()) { - return matches; - } - // Action matches. - if (!action.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean actionMatch = matching[index][0]; - if (actionMatch && media.getPoses().isEmpty()) { - matches.add(media); - } - index++; - } - // For actions, the action is required. - return matches; - } - // Pose matches. - if (!pose.isEmpty()) { - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - boolean poseMatch = matching[index][1]; - if (poseMatch && media.getActions().isEmpty()) { - matches.add(media); - } - index++; - } - if (!matches.isEmpty()) { - return matches; - } - } - // Default matches. - index = 0; - for (AvatarMedia media : this.mediaConfig.values()) { - if (!media.isAudio()) { - continue; - } - if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) - && (media.getActions().isEmpty() || media.getActions().contains("none")) - && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { - matches.add(media); - } - index++; - } - return matches; - } + boolean[][] matching = new boolean[this.mediaConfig.size()][4]; + int index = 0; + // All match. + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean emotionMatch = media.getEmotions().contains(emotion) || (none && media.getEmotions().isEmpty()); + if (emotionMatch && emotion.equals("RAGE") && media.getEmotions().contains("COURAGE")) { + // Both contain "rage". + emotionMatch = false; + } + if (emotionMatch && emotion.equals("LIKE") && media.getEmotions().contains("DISLIKE")) { + // Both contain "like". + emotionMatch = false; + } + boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); + boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); + boolean pose2Match = (!pose2.isEmpty() && media.getPoses().contains(pose2)) || pose2.isEmpty(); + if (!pose2Match && pose2.equals("talking")) { + pose2Match = media.getTalking(); + } else if (media.getTalking() && !talking) { + pose2Match = false; + } + matching[index][0] = emotionMatch; + matching[index][1] = actionMatch; + matching[index][2] = poseMatch; + matching[index][3] = pose2Match; + index++; + if (emotionMatch && actionMatch && poseMatch && pose2Match) { + matches.add(media); + } + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 and pose matches. + if (!pose2.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean poseMatch = matching[index][2]; + boolean pose2Match = matching[index][3]; + if (poseMatch && pose2Match) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 and emotion matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + boolean pose2Match = matching[index][3]; + if (emotionMatch && pose2Match) { + if (!media.getPoses().isEmpty()) { + index++; + continue; + } + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean pose2Match = matching[index][3]; + if (pose2Match) { + if (!media.getPoses().isEmpty()) { + index++; + continue; + } + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose2 any matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + boolean pose2Match = matching[index][3]; + if (pose2Match) { + matches.add(media); + } + index++; + } + // For pose2, the pose is required (i.e. talking). + return matches; + } + // Action and pose matches. + if (!action.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean actionMatch = matching[index][1]; + boolean poseMatch = matching[index][2]; + if (actionMatch && poseMatch) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Action matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean actionMatch = matching[index][1]; + if (actionMatch + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + // For actions, the action is required. + return matches; + } + // Pose and emotion matches. + if (!pose.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + boolean poseMatch = matching[index][2]; + if (poseMatch && emotionMatch && media.getActions().isEmpty()) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Pose matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean poseMatch = matching[index][2]; + if (poseMatch && media.getActions().isEmpty() + && (media.getEmotions().isEmpty() || media.getEmotions().contains("NONE"))) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + } + // Emotion matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + boolean emotionMatch = matching[index][0]; + if (emotionMatch + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + // Default matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (media.isAudio()) { + index++; + continue; + } + if (!talking && media.getTalking()) { + index++; + continue; + } + if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + return matches; + } /** - * randomMatch - * - * @param matches List - * @return AvatarMedia - * */ - public AvatarMedia randomMatch(List matches) { - List formatMatches = new ArrayList(); - String format = "mp4"; - if (this.avatarFormat != null && !this.avatarFormat.isEmpty()) { - format = this.avatarFormat; - } - for (AvatarMedia media : matches) { - if (media.getType().indexOf(format) != -1) { - formatMatches.add(media); - } - } - if (formatMatches.isEmpty()) { - List hdMatches = new ArrayList(); - for (AvatarMedia media : matches) { - if (this.avatarHD && media.getHD()) { - hdMatches.add(media); - } else if (!this.avatarHD && !media.getHD()) { - hdMatches.add(media); - } - } - if (!hdMatches.isEmpty()) { - return Utils.random(hdMatches); - } - return Utils.random(matches); - } else { - List hdMatches = new ArrayList(); - for (AvatarMedia media : formatMatches) { - if (this.avatarHD && media.getHD()) { - hdMatches.add(media); - } else if (!this.avatarHD && !media.getHD()) { - hdMatches.add(media); - } - } - if (!hdMatches.isEmpty()) { - return Utils.random(hdMatches); - } - return Utils.random(formatMatches); - } - } + * Find an audio media that matches the action or pose. + * + * @param action String + * @param pose String + * @return List + */ + public List getAudio(String action, String pose) { + if (action == null) { + action = ""; + } + if (pose == null) { + pose = ""; + } + List matches = new ArrayList(); + + boolean[][] matching = new boolean[this.mediaConfig.size()][2]; + int index = 0; + // All match. + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean actionMatch = (!action.isEmpty() && media.getActions().contains(action)) || (action.isEmpty() && media.getActions().isEmpty()); + boolean poseMatch = (!pose.isEmpty() && media.getPoses().contains(pose)) || (pose.isEmpty() && media.getPoses().isEmpty()); + matching[index][0] = actionMatch; + matching[index][1] = poseMatch; + index++; + if (actionMatch && poseMatch) { + matches.add(media); + } + } + if (!matches.isEmpty()) { + return matches; + } + // Action matches. + if (!action.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean actionMatch = matching[index][0]; + if (actionMatch && media.getPoses().isEmpty()) { + matches.add(media); + } + index++; + } + // For actions, the action is required. + return matches; + } + // Pose matches. + if (!pose.isEmpty()) { + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + boolean poseMatch = matching[index][1]; + if (poseMatch && media.getActions().isEmpty()) { + matches.add(media); + } + index++; + } + if (!matches.isEmpty()) { + return matches; + } + } + // Default matches. + index = 0; + for (AvatarMedia media : this.mediaConfig.values()) { + if (!media.isAudio()) { + continue; + } + if ((media.getEmotions().isEmpty() || media.getEmotions().contains("NONE")) + && (media.getActions().isEmpty() || media.getActions().contains("none")) + && (media.getPoses().isEmpty() || media.getPoses().contains("none"))) { + matches.add(media); + } + index++; + } + return matches; + } /** - * getBackground - * - * @return String - * */ - public String getBackground(){ - return background; - } + * randomMatch + * + * @param matches List + * @return AvatarMedia + */ + public AvatarMedia randomMatch(List matches) { + List formatMatches = new ArrayList(); + String format = "mp4"; + if (this.avatarFormat != null && !this.avatarFormat.isEmpty()) { + format = this.avatarFormat; + } + for (AvatarMedia media : matches) { + if (media.getType().indexOf(format) != -1) { + formatMatches.add(media); + } + } + if (formatMatches.isEmpty()) { + List hdMatches = new ArrayList(); + for (AvatarMedia media : matches) { + if (this.avatarHD && media.getHD()) { + hdMatches.add(media); + } else if (!this.avatarHD && !media.getHD()) { + hdMatches.add(media); + } + } + if (!hdMatches.isEmpty()) { + return Utils.random(hdMatches); + } + return Utils.random(matches); + } else { + List hdMatches = new ArrayList(); + for (AvatarMedia media : formatMatches) { + if (this.avatarHD && media.getHD()) { + hdMatches.add(media); + } else if (!this.avatarHD && !media.getHD()) { + hdMatches.add(media); + } + } + if (!hdMatches.isEmpty()) { + return Utils.random(hdMatches); + } + return Utils.random(formatMatches); + } + } - /** - * getIcon - * - * @return String - * */ - public String getIcon(){ - return icon; - } + /** + * getBackground + * + * @return String + */ + public String getBackground() { + return background; + } + + /** + * getIcon + * + * @return String + */ + public String getIcon() { + return icon; + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java index 58cab32..a480e48 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarMedia.java @@ -29,102 +29,107 @@ import org.w3c.dom.Element; * The media is the short URL to the media file on the server. */ public class AvatarMedia extends Config { - public String mediaId; - public String name; - public String types; - public String media; - public String emotions; - public String actions; - public String poses; - public boolean hd; - public boolean talking; - - public void parseXML(Element element) { - super.parseXML(element); - - this.mediaId = element.getAttribute("mediaId"); - this.name = element.getAttribute("name"); - this.types = element.getAttribute("type"); - this.media = element.getAttribute("media"); - this.emotions = element.getAttribute("emotions"); - this.actions = element.getAttribute("actions"); - this.poses = element.getAttribute("poses"); - this.hd = Boolean.valueOf(element.getAttribute("hd")); - this.talking = Boolean.valueOf(element.getAttribute("talking")); - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public boolean getHD() { - return hd; - } - public boolean isImage() { - return this.type.contains("image") || this.type.isEmpty(); - } - - public boolean isVideo() { - return this.type != null && this.type.indexOf("video") != -1; - } - - public boolean isAudio() { - return this.type != null && this.type.indexOf("audio") != -1; - } - public String getType() { - return type; - } - public String getEmotions() { - return emotions; - } - - public void setEmotions(String emotions) { - this.emotions = emotions; - } - public String getActions() { - return actions; - } - - public String getPoses() { - return poses; - } - - public void setPoses(String poses) { - this.poses = poses; - } - - public void setActions(String actions) { - this.actions = actions; - } - public boolean getTalking() { - return talking; - } - - public void setTalking(boolean talking) { - this.talking = talking; - } + public String mediaId; + public String name; + public String types; + public String media; + public String emotions; + public String actions; + public String poses; + public boolean hd; + public boolean talking; + + public void parseXML(Element element) { + super.parseXML(element); + + this.mediaId = element.getAttribute("mediaId"); + this.name = element.getAttribute("name"); + this.types = element.getAttribute("type"); + this.media = element.getAttribute("media"); + this.emotions = element.getAttribute("emotions"); + this.actions = element.getAttribute("actions"); + this.poses = element.getAttribute("poses"); + this.hd = Boolean.valueOf(element.getAttribute("hd")); + this.talking = Boolean.valueOf(element.getAttribute("talking")); + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public boolean getHD() { + return hd; + } + + public boolean isImage() { + return this.type.contains("image") || this.type.isEmpty(); + } + + public boolean isVideo() { + return this.type != null && this.type.indexOf("video") != -1; + } + + public boolean isAudio() { + return this.type != null && this.type.indexOf("audio") != -1; + } + + public String getType() { + return type; + } + + public String getEmotions() { + return emotions; + } + + public void setEmotions(String emotions) { + this.emotions = emotions; + } + + public String getActions() { + return actions; + } + + public String getPoses() { + return poses; + } + + public void setPoses(String poses) { + this.poses = poses; + } + + public void setActions(String actions) { + this.actions = actions; + } + + public boolean getTalking() { + return talking; + } + + public void setTalking(boolean talking) { + this.talking = talking; + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java index e947ee2..81a7334 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarMessage.java @@ -29,52 +29,52 @@ import java.io.StringWriter; * This object can be converted to and from XML for usage with the web API. */ public class AvatarMessage extends Config { - public String message; - public String avatar; - public String emote; - public String action; - public String pose; - public boolean speak; - public String voice; - public String format; - public boolean hd; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } + public String message; + public String avatar; + public String emote; + public String action; + public String pose; + public boolean speak; + public String voice; + public String format; + public boolean hd; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.message != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.message)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java index 5e672e1..64ff99b 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/BotModeConfig.java @@ -27,31 +27,31 @@ import org.w3c.dom.Element; * DTO for XML bot mode config. */ public class BotModeConfig extends Config { - - public String mode; - public String bot; - - public void parseXML(Element element) { - super.parseXML(element); - - this.mode = element.getAttribute("mode"); - this.bot = element.getAttribute("bot"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + + public String mode; + public String bot; + + public void parseXML(Element element) { + super.parseXML(element); + + this.mode = element.getAttribute("mode"); + this.bot = element.getAttribute("bot"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java index 480720c..867d9d7 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/BrowseConfig.java @@ -24,50 +24,50 @@ import java.io.StringWriter; * DTO for XML browse options. */ public class BrowseConfig extends Config { - public String types; - public String typeFilter; - public String category; - public String tag; - public String filter; - public String userFilter; - public String sort; - public String restrict; - public String page; - public String contentRating; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String types; + public String typeFilter; + public String category; + public String tag; + public String filter; + public String userFilter; + public String sort; + public String restrict; + public String page; + public String contentRating; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java index ba57ec1..98126b9 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChannelConfig.java @@ -26,53 +26,53 @@ import org.w3c.dom.Element; * DTO for XML channel config. */ public class ChannelConfig extends WebMediumConfig { - public String types; - public String videoAccessMode; - public String audioAccessMode; - public String messages; - public String usersOnline; - public String adminsOnline; + public String types; + public String videoAccessMode; + public String audioAccessMode; + public String messages; + public String usersOnline; + public String adminsOnline; - @Override - public String getType() { - return "channel"; - } + @Override + public String getType() { + return "channel"; + } - @Override - public String stats() { - return this.usersOnline + " users online, " + this.adminsOnline + " admins"; - } - - public WebMediumConfig credentials() { - ChannelConfig config = new ChannelConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.types = element.getAttribute("type"); - this.videoAccessMode = element.getAttribute("videoAccessMode"); - this.audioAccessMode = element.getAttribute("audioAccessMode"); - this.messages = element.getAttribute("messages"); - this.usersOnline = element.getAttribute("usersOnline"); - this.adminsOnline = element.getAttribute("adminsOnline"); - } + @Override + public String stats() { + return this.usersOnline + " users online, " + this.adminsOnline + " admins"; + } + + public WebMediumConfig credentials() { + ChannelConfig config = new ChannelConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.types = element.getAttribute("type"); + this.videoAccessMode = element.getAttribute("videoAccessMode"); + this.audioAccessMode = element.getAttribute("audioAccessMode"); + this.messages = element.getAttribute("messages"); + this.usersOnline = element.getAttribute("usersOnline"); + this.adminsOnline = element.getAttribute("adminsOnline"); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java index c2ce860..fec4518 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChatConfig.java @@ -27,73 +27,73 @@ import java.io.StringWriter; /** * DTO for XML chat config. */ -public class ChatConfig extends Config { - public String conversation; - public boolean correction; - public boolean offensive; - public boolean disconnect; - public String emote; - public String action; - public String message; - public boolean speak; - public boolean includeQuestion; - public boolean avatarHD; - public String avatarFormat; - public String avatar; - public String language; - public String voice; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } +public class ChatConfig extends Config { + public String conversation; + public boolean correction; + public boolean offensive; + public boolean disconnect; + public String emote; + public String action; + public String message; + public boolean speak; + public boolean includeQuestion; + public boolean avatarHD; + public String avatarFormat; + public String avatar; + public String language; + public String voice; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.message != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.message)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java index 9e93cab..d47f7e6 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java @@ -26,81 +26,81 @@ import org.w3c.dom.Node; /** * DTO for XML chat config. */ -public class ChatResponse extends Config { - public String conversation; - public String message; - public String question; - public String emote; - public String action; - public String pose; - public String command; - public String avatar; - public String avatar2; - public String avatar3; - public String avatar4; - public String avatar5; - public String avatarType; - public String avatarTalk; - public String avatarTalkType; - public String avatarAction; - public String avatarActionType; - public String avatarActionAudio; - public String avatarActionAudioType; - public String avatarAudio; - public String avatarAudioType; - public String avatarBackground; - public String speech; - - public boolean isVideo() { - return this.avatarType != null && this.avatarType.indexOf("video") != -1; - } - - public boolean isVideoTalk() { - return this.avatarTalkType != null && this.avatarTalkType.indexOf("video") != -1; - } +public class ChatResponse extends Config { + public String conversation; + public String message; + public String question; + public String emote; + public String action; + public String pose; + public String command; + public String avatar; + public String avatar2; + public String avatar3; + public String avatar4; + public String avatar5; + public String avatarType; + public String avatarTalk; + public String avatarTalkType; + public String avatarAction; + public String avatarActionType; + public String avatarActionAudio; + public String avatarActionAudioType; + public String avatarAudio; + public String avatarAudioType; + public String avatarBackground; + public String speech; - public void parseXML(Element element) { - this.conversation = element.getAttribute("conversation"); - this.emote = element.getAttribute("emote"); - this.action = element.getAttribute("action"); - this.pose = element.getAttribute("pose"); - this.avatar = element.getAttribute("avatar"); - this.avatar2 = element.getAttribute("avatar2"); - this.avatar3 = element.getAttribute("avatar3"); - this.avatar4 = element.getAttribute("avatar4"); - this.avatar5 = element.getAttribute("avatar5"); - this.avatarType = element.getAttribute("avatarType"); - this.avatarTalk = element.getAttribute("avatarTalk"); - this.avatarTalkType = element.getAttribute("avatarTalkType"); - this.avatarAction = element.getAttribute("avatarAction"); - this.avatarActionType = element.getAttribute("avatarActionType"); - this.avatarActionAudio = element.getAttribute("avatarActionAudio"); - this.avatarActionAudioType = element.getAttribute("avatarActionAudioType"); - this.avatarAudio = element.getAttribute("avatarAudio"); - this.avatarAudioType = element.getAttribute("avatarAudioType"); - this.avatarBackground = element.getAttribute("avatarBackground"); - this.speech = element.getAttribute("speech"); - this.command = element.getAttribute("command"); + public boolean isVideo() { + return this.avatarType != null && this.avatarType.indexOf("video") != -1; + } - Node node = element.getElementsByTagName("message").item(0); - if (node != null) { - this.message = node.getTextContent(); - } - node = element.getElementsByTagName("question").item(0); - if (node != null) { - this.question = node.getTextContent(); - } - } - - public ZSONObject getCommand(){ - if (this.command == null || this.command.equals("")){ - return null; - } - try { - return new ZSONObject(); - } catch (ZSONException exception) { - exception.printStackTrace(); - } - return null; - } + public boolean isVideoTalk() { + return this.avatarTalkType != null && this.avatarTalkType.indexOf("video") != -1; + } + + public void parseXML(Element element) { + this.conversation = element.getAttribute("conversation"); + this.emote = element.getAttribute("emote"); + this.action = element.getAttribute("action"); + this.pose = element.getAttribute("pose"); + this.avatar = element.getAttribute("avatar"); + this.avatar2 = element.getAttribute("avatar2"); + this.avatar3 = element.getAttribute("avatar3"); + this.avatar4 = element.getAttribute("avatar4"); + this.avatar5 = element.getAttribute("avatar5"); + this.avatarType = element.getAttribute("avatarType"); + this.avatarTalk = element.getAttribute("avatarTalk"); + this.avatarTalkType = element.getAttribute("avatarTalkType"); + this.avatarAction = element.getAttribute("avatarAction"); + this.avatarActionType = element.getAttribute("avatarActionType"); + this.avatarActionAudio = element.getAttribute("avatarActionAudio"); + this.avatarActionAudioType = element.getAttribute("avatarActionAudioType"); + this.avatarAudio = element.getAttribute("avatarAudio"); + this.avatarAudioType = element.getAttribute("avatarAudioType"); + this.avatarBackground = element.getAttribute("avatarBackground"); + this.speech = element.getAttribute("speech"); + this.command = element.getAttribute("command"); + + Node node = element.getElementsByTagName("message").item(0); + if (node != null) { + this.message = node.getTextContent(); + } + node = element.getElementsByTagName("question").item(0); + if (node != null) { + this.question = node.getTextContent(); + } + } + + public ZSONObject getCommand() { + if (this.command == null || this.command.equals("")) { + return null; + } + try { + return new ZSONObject(); + } catch (ZSONException exception) { + exception.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/Config.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/Config.java index dac4c7b..331cee4 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/Config.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/Config.java @@ -27,63 +27,63 @@ import org.w3c.dom.Element; * DTO for XML config. */ public class Config implements Cloneable { - public String application; - public String domain; - public String user; - public String token; - public String instance; - public String type; - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException exception) { - throw new Error(exception); - } - } - - public void addCredentials(SDKConnection connection) { - this.application = connection.getCredentials().getApplicationId(); - if (this.user == null && connection.getUser() != null) { - this.user = connection.getUser().user; - this.token = connection.getUser().token; - } - if (this.domain == null && connection.getDomain() != null) { - this.domain = connection.getDomain().id; - } - } - - public String toXML() { - return ""; - } - - public void parseXML(Element element) { - this.application = element.getAttribute("application"); - this.domain = element.getAttribute("domain"); - this.user = element.getAttribute("user"); - this.token = element.getAttribute("token"); - this.instance = element.getAttribute("instance"); - this.type = element.getAttribute("type"); - } - - public void writeCredentials(StringWriter writer) { - if (this.user != null && this.user.length() > 0) { - writer.write(" user=\"" + this.user + "\""); - } - if (this.token != null && this.token.length() > 0) { - writer.write(" token=\"" + this.token + "\""); - } - if (this.type != null && !this.type.equals("")) { - writer.write(" type=\"" + this.type + "\""); - } - if (this.instance != null && !this.instance.equals("")) { - writer.write(" instance=\"" + this.instance + "\""); - } - if (this.application != null && !this.application.equals("")) { - writer.write(" application=\"" + this.application + "\""); - } - if (this.domain != null && !this.domain.equals("")) { - writer.write(" domain=\"" + this.domain + "\""); - } - } + public String application; + public String domain; + public String user; + public String token; + public String instance; + public String type; + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException exception) { + throw new Error(exception); + } + } + + public void addCredentials(SDKConnection connection) { + this.application = connection.getCredentials().getApplicationId(); + if (this.user == null && connection.getUser() != null) { + this.user = connection.getUser().user; + this.token = connection.getUser().token; + } + if (this.domain == null && connection.getDomain() != null) { + this.domain = connection.getDomain().id; + } + } + + public String toXML() { + return ""; + } + + public void parseXML(Element element) { + this.application = element.getAttribute("application"); + this.domain = element.getAttribute("domain"); + this.user = element.getAttribute("user"); + this.token = element.getAttribute("token"); + this.instance = element.getAttribute("instance"); + this.type = element.getAttribute("type"); + } + + public void writeCredentials(StringWriter writer) { + if (this.user != null && this.user.length() > 0) { + writer.write(" user=\"" + this.user + "\""); + } + if (this.token != null && this.token.length() > 0) { + writer.write(" token=\"" + this.token + "\""); + } + if (this.type != null && !this.type.equals("")) { + writer.write(" type=\"" + this.type + "\""); + } + if (this.instance != null && !this.instance.equals("")) { + writer.write(" instance=\"" + this.instance + "\""); + } + if (this.application != null && !this.application.equals("")) { + writer.write(" application=\"" + this.application + "\""); + } + if (this.domain != null && !this.domain.equals("")) { + writer.write(" domain=\"" + this.domain + "\""); + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java index 21c1a49..349ef72 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ContentConfig.java @@ -28,35 +28,35 @@ import org.w3c.dom.Node; * DTO for XML content config. */ public class ContentConfig extends Config { - - public String types; - public String name; - public String icon; - public String description; - - public void parseXML(Element element) { - super.parseXML(element); - - this.types = element.getAttribute("type"); - this.name = element.getAttribute("name"); - this.icon = element.getAttribute("icon"); - - Node node = element.getElementsByTagName("description").item(0); - if (node != null) { - this.description = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + + public String types; + public String name; + public String icon; + public String description; + + public void parseXML(Element element) { + super.parseXML(element); + + this.types = element.getAttribute("type"); + this.name = element.getAttribute("name"); + this.icon = element.getAttribute("icon"); + + Node node = element.getElementsByTagName("description").item(0); + if (node != null) { + this.description = node.getTextContent(); + } + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java index 893cd6f..9f854f9 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ConversationConfig.java @@ -33,26 +33,26 @@ import org.w3c.dom.NodeList; * DTO for XML conversation config. */ public class ConversationConfig extends Config { - public String id; - public String creationDate; - public String types; - - public List input; - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.types = element.getAttribute("type"); - - NodeList nodes = element.getElementsByTagName("input"); - if (nodes != null && nodes.getLength() > 0) { - this.input = new ArrayList(); - for (int index = 0; index < nodes.getLength(); index++) { - Element node = (Element)nodes.item(index); - InputConfig config = new InputConfig(); - config.parseXML(node); - this.input.add(config); - } - } - } + public String id; + public String creationDate; + public String types; + + public List input; + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.creationDate = element.getAttribute("creationDate"); + this.types = element.getAttribute("type"); + + NodeList nodes = element.getElementsByTagName("input"); + if (nodes != null && nodes.getLength() > 0) { + this.input = new ArrayList(); + for (int index = 0; index < nodes.getLength(); index++) { + Element node = (Element) nodes.item(index); + InputConfig config = new InputConfig(); + config.parseXML(node); + this.input.add(config); + } + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java index 6eee6ee..46d4cb6 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/DomainConfig.java @@ -26,31 +26,31 @@ import org.w3c.dom.Element; * DTO for XML domain config. */ public class DomainConfig extends WebMediumConfig { - public String creationMode; - - public String getType() { - return "domain"; - } - - public WebMediumConfig credentials() { - DomainConfig config = new DomainConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.creationMode = element.getAttribute("creationMode"); - } + public String creationMode; + + public String getType() { + return "domain"; + } + + public WebMediumConfig credentials() { + DomainConfig config = new DomainConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.creationMode = element.getAttribute("creationMode"); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java index 679f144..aab18b4 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ForumConfig.java @@ -26,43 +26,43 @@ import org.w3c.dom.Element; * DTO for XML forum config. */ public class ForumConfig extends WebMediumConfig { - public String replyAccessMode; - public String postAccessMode; - public String posts; - - public String getType() { - return "forum"; - } + public String replyAccessMode; + public String postAccessMode; + public String posts; - @Override - public String stats() { - return this.posts + " posts"; - } - - public WebMediumConfig credentials() { - ForumConfig config = new ForumConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.replyAccessMode = element.getAttribute("replyAccessMode"); - this.postAccessMode = element.getAttribute("postAccessMode"); - this.posts = element.getAttribute("posts"); - } + public String getType() { + return "forum"; + } + + @Override + public String stats() { + return this.posts + " posts"; + } + + public WebMediumConfig credentials() { + ForumConfig config = new ForumConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.replyAccessMode = element.getAttribute("replyAccessMode"); + this.postAccessMode = element.getAttribute("postAccessMode"); + this.posts = element.getAttribute("posts"); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java index e8133da..70ba726 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ForumPostConfig.java @@ -35,172 +35,173 @@ import org.w3c.dom.NodeList; /** * DTO for XML forum post config. */ -public class ForumPostConfig extends Config { - public String id; - public String topic; - public String summary; - public String details; - public String detailsText; - public String forum; - public String tags; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public boolean isAdmin; - public boolean isFlagged; - public String flaggedReason; - public boolean isFeatured; - public String creator; - public String creationDate; - public String views; - public String dailyViews; - public String weeklyViews; - public String monthlyViews; - public String replyCount; - public String parent; - public String avatar; - public List replies; - - public boolean equals(Object object) { - if (object instanceof ForumPostConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((ForumPostConfig)object).id); - } - return false; - } +public class ForumPostConfig extends Config { + public String id; + public String topic; + public String summary; + public String details; + public String detailsText; + public String forum; + public String tags; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public boolean isAdmin; + public boolean isFlagged; + public String flaggedReason; + public boolean isFeatured; + public String creator; + public String creationDate; + public String views; + public String dailyViews; + public String weeklyViews; + public String monthlyViews; + public String replyCount; + public String parent; + public String avatar; + public List replies; - @Override - public int hashCode() { - return Objects.hash(id, topic, summary, details, detailsText, forum, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isFeatured, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, replyCount, parent, avatar, replies); - } + public boolean equals(Object object) { + if (object instanceof ForumPostConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((ForumPostConfig) object).id); + } + return false; + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + @Override + public int hashCode() { + return Objects.hash(id, topic, summary, details, detailsText, forum, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isFeatured, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, replyCount, parent, avatar, replies); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.topic != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.topic)); - writer.write(""); - } - if (this.details != null) { - String text = this.details; - writer.write("
"); - writer.write(Utils.escapeHTML(text)); - writer.write("
"); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.parent = element.getAttribute("parent"); - this.forum = element.getAttribute("forum"); - this.views = element.getAttribute("views"); - this.dailyViews = element.getAttribute("dailyViews"); - this.weeklyViews = element.getAttribute("weeklyViews"); - this.monthlyViews = element.getAttribute("monthlyViews"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.replyCount = element.getAttribute("replyCount"); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("summary").item(0); - if (node != null) { - this.summary = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("detailsText").item(0); - if (node != null) { - this.detailsText = node.getTextContent(); - } - node = element.getElementsByTagName("topic").item(0); - if (node != null) { - this.topic = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - NodeList nodes = element.getElementsByTagName("replies"); - if (nodes != null && nodes.getLength() > 0) { - this.replies = new ArrayList(); - for (int index = 0; index < nodes.getLength(); index++) { - Element reply = (Element)nodes.item(index); - ForumPostConfig config = new ForumPostConfig(); - config.parseXML(reply); - this.replies.add(config); - } - } - } - public ForumPostConfig credentials() { - ForumPostConfig config = new ForumPostConfig(); - config.id = this.id; - return config; - } + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.topic != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.topic)); + writer.write(""); + } + if (this.details != null) { + String text = this.details; + writer.write("
"); + writer.write(Utils.escapeHTML(text)); + writer.write("
"); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.parent = element.getAttribute("parent"); + this.forum = element.getAttribute("forum"); + this.views = element.getAttribute("views"); + this.dailyViews = element.getAttribute("dailyViews"); + this.weeklyViews = element.getAttribute("weeklyViews"); + this.monthlyViews = element.getAttribute("monthlyViews"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.replyCount = element.getAttribute("replyCount"); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("summary").item(0); + if (node != null) { + this.summary = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("detailsText").item(0); + if (node != null) { + this.detailsText = node.getTextContent(); + } + node = element.getElementsByTagName("topic").item(0); + if (node != null) { + this.topic = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + NodeList nodes = element.getElementsByTagName("replies"); + if (nodes != null && nodes.getLength() > 0) { + this.replies = new ArrayList(); + for (int index = 0; index < nodes.getLength(); index++) { + Element reply = (Element) nodes.item(index); + ForumPostConfig config = new ForumPostConfig(); + config.parseXML(reply); + this.replies.add(config); + } + } + } + + public ForumPostConfig credentials() { + ForumPostConfig config = new ForumPostConfig(); + config.id = this.id; + return config; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayTimestamp(date); + } catch (Exception exception) { + return creationDate; + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java index 6fedbf0..1d5d9b7 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/GraphicConfig.java @@ -7,59 +7,61 @@ import org.w3c.dom.Element; /** * DTO for XML graphic config. */ -public class GraphicConfig extends WebMediumConfig{ - public String media; - public String fileName; - public String fileType; - - - @Override - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } +public class GraphicConfig extends WebMediumConfig { + public String media; + public String fileName; + public String fileType; - @Override - public String getType() { - return "graphic"; - } - @Override - public WebMediumConfig credentials() { - GraphicConfig config = new GraphicConfig(); - config.id = this.id; - return config; - } - public void parseXML(Element element) { - super.parseXML(element); - this.media = element.getAttribute("media"); - this.fileName = element.getAttribute("fileName"); - this.fileType = element.getAttribute("fileType"); + @Override + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + @Override + public String getType() { + return "graphic"; + } + + @Override + public WebMediumConfig credentials() { + GraphicConfig config = new GraphicConfig(); + config.id = this.id; + return config; + } + + public void parseXML(Element element) { + super.parseXML(element); + this.media = element.getAttribute("media"); + this.fileName = element.getAttribute("fileName"); + this.fileType = element.getAttribute("fileType"); // Node node = element.getElementsByTagName("media").item(0); // if (node != null) { // this.media = node.getTextContent(); // } - } - public boolean isVideo() { - return this.fileType != null && this.fileType.indexOf("video") != -1; - - } - - public boolean isAudio() { - return this.fileType != null && this.fileType.indexOf("audio") != -1; - } + } + + public boolean isVideo() { + return this.fileType != null && this.fileType.indexOf("video") != -1; + + } + + public boolean isAudio() { + return this.fileType != null && this.fileType.indexOf("audio") != -1; + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java index 9c99d0f..329707a 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/InputConfig.java @@ -31,31 +31,31 @@ import java.util.Locale; * DTO for XML input config. */ public class InputConfig extends Config { - public String id; - public String creationDate; - public String speaker; - public String target; - public String value; - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.speaker = element.getAttribute("speaker"); - this.target = element.getAttribute("target"); - - Node node = element.getElementsByTagName("value").item(0); - if (node != null) { - this.value = node.getTextContent(); - } - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTime(date); - } catch (Exception exception) { - return creationDate; - } - } + public String id; + public String creationDate; + public String speaker; + public String target; + public String value; + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.creationDate = element.getAttribute("creationDate"); + this.speaker = element.getAttribute("speaker"); + this.target = element.getAttribute("target"); + + Node node = element.getElementsByTagName("value").item(0); + if (node != null) { + this.value = node.getTextContent(); + } + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayTime(date); + } catch (Exception exception) { + return creationDate; + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java index 59e8f80..7820784 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/InstanceConfig.java @@ -27,69 +27,69 @@ import org.w3c.dom.Node; * DTO for XML bot instance config. */ public class InstanceConfig extends WebMediumConfig { - public String size; - public String instanceAvatar; - public boolean allowForking; - public boolean hasAPI; - public String template; - public int rank; - public int wins; - public int losses; - - public String getType() { - return "instance"; - } + public String size; + public String instanceAvatar; + public boolean allowForking; + public boolean hasAPI; + public String template; + public int rank; + public int wins; + public int losses; - @Override - public String stats() { - return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month"; - } + public String getType() { + return "instance"; + } - @Override - public InstanceConfig credentials() { - InstanceConfig config = new InstanceConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - writer.write(this.template); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.allowForking = Boolean.valueOf(element.getAttribute("allowForking")); - this.hasAPI = Boolean.valueOf(element.getAttribute("hasAPI")); - this.size = element.getAttribute("size"); - this.instanceAvatar = element.getAttribute("instanceAvatar"); - if (element.getAttribute("rank") != null && element.getAttribute("rank").trim().length() > 0) { - this.rank = Integer.valueOf(element.getAttribute("rank")); - } - if (element.getAttribute("wins") != null && element.getAttribute("wins").trim().length() > 0) { - this.wins = Integer.valueOf(element.getAttribute("wins")); - } - if (element.getAttribute("losses") != null && element.getAttribute("losses").trim().length() > 0) { - this.losses = Integer.valueOf(element.getAttribute("losses")); - } - - Node node = element.getElementsByTagName("template").item(0); - if (node != null) { - this.template = node.getTextContent(); - } - } + @Override + public String stats() { + return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month"; + } + + @Override + public InstanceConfig credentials() { + InstanceConfig config = new InstanceConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + writer.write(this.template); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.allowForking = Boolean.valueOf(element.getAttribute("allowForking")); + this.hasAPI = Boolean.valueOf(element.getAttribute("hasAPI")); + this.size = element.getAttribute("size"); + this.instanceAvatar = element.getAttribute("instanceAvatar"); + if (element.getAttribute("rank") != null && element.getAttribute("rank").trim().length() > 0) { + this.rank = Integer.valueOf(element.getAttribute("rank")); + } + if (element.getAttribute("wins") != null && element.getAttribute("wins").trim().length() > 0) { + this.wins = Integer.valueOf(element.getAttribute("wins")); + } + if (element.getAttribute("losses") != null && element.getAttribute("losses").trim().length() > 0) { + this.losses = Integer.valueOf(element.getAttribute("losses")); + } + + Node node = element.getElementsByTagName("template").item(0); + if (node != null) { + this.template = node.getTextContent(); + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java index 014f21d..33fd536 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/IssueConfig.java @@ -34,158 +34,159 @@ import java.util.Objects; * DTO for XML issue config. */ public class IssueConfig extends Config { - public String id; - public String title; - public String priority; - public String summary; - public String details; - public String detailsText; - public String tracker; - public String tags; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public boolean isAdmin; - public boolean isFlagged; - public String flaggedReason; - public boolean isPriority; - public String creator; - public String creationDate; - public String views; - public String dailyViews; - public String weeklyViews; - public String monthlyViews; - public String avatar; - - public boolean equals(Object object) { - if (object instanceof IssueConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((IssueConfig)object).id); - } - return false; - } + public String id; + public String title; + public String priority; + public String summary; + public String details; + public String detailsText; + public String tracker; + public String tags; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public boolean isAdmin; + public boolean isFlagged; + public String flaggedReason; + public boolean isPriority; + public String creator; + public String creationDate; + public String views; + public String dailyViews; + public String weeklyViews; + public String monthlyViews; + public String avatar; - @Override - public int hashCode() { - return Objects.hash(id, title, priority, summary, details, detailsText, tracker, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isPriority, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, avatar); - } + public boolean equals(Object object) { + if (object instanceof IssueConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((IssueConfig) object).id); + } + return false; + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + @Override + public int hashCode() { + return Objects.hash(id, title, priority, summary, details, detailsText, tracker, tags, thumbsUp, thumbsDown, stars, isAdmin, isFlagged, flaggedReason, isPriority, creator, creationDate, views, dailyViews, weeklyViews, monthlyViews, avatar); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.title != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.title)); - writer.write(""); - } - if (this.details != null) { - String text = this.details; - writer.write("
"); - writer.write(Utils.escapeHTML(text)); - writer.write("
"); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.tracker = element.getAttribute("tracker"); - this.priority = element.getAttribute("priority"); - this.views = element.getAttribute("views"); - this.dailyViews = element.getAttribute("dailyViews"); - this.weeklyViews = element.getAttribute("weeklyViews"); - this.monthlyViews = element.getAttribute("monthlyViews"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isPriority = Boolean.valueOf(element.getAttribute("isPriority")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("summary").item(0); - if (node != null) { - this.summary = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("detailsText").item(0); - if (node != null) { - this.detailsText = node.getTextContent(); - } - node = element.getElementsByTagName("title").item(0); - if (node != null) { - this.title = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - } - public IssueConfig credentials() { - IssueConfig config = new IssueConfig(); - config.id = this.id; - return config; - } + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return creationDate; - } - } + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.title != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.title)); + writer.write(""); + } + if (this.details != null) { + String text = this.details; + writer.write("
"); + writer.write(Utils.escapeHTML(text)); + writer.write("
"); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.tracker = element.getAttribute("tracker"); + this.priority = element.getAttribute("priority"); + this.views = element.getAttribute("views"); + this.dailyViews = element.getAttribute("dailyViews"); + this.weeklyViews = element.getAttribute("weeklyViews"); + this.monthlyViews = element.getAttribute("monthlyViews"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isPriority = Boolean.valueOf(element.getAttribute("isPriority")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("summary").item(0); + if (node != null) { + this.summary = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("detailsText").item(0); + if (node != null) { + this.detailsText = node.getTextContent(); + } + node = element.getElementsByTagName("title").item(0); + if (node != null) { + this.title = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + } + + public IssueConfig credentials() { + IssueConfig config = new IssueConfig(); + config.id = this.id; + return config; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayTimestamp(date); + } catch (Exception exception) { + return creationDate; + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java index 451d66c..19d0959 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/IssueTrackerConfig.java @@ -26,38 +26,38 @@ import java.io.StringWriter; * DTO for XML issue tracker config. */ public class IssueTrackerConfig extends WebMediumConfig { - public String createAccessMode; - public String issues; - - public String getType() { - return "issuetracker"; - } - - @Override - public String stats() { - return this.issues + " issues"; - } - - public WebMediumConfig credentials() { - IssueTrackerConfig config = new IssueTrackerConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element) { - super.parseXML(element); - this.createAccessMode = element.getAttribute("createAccessMode"); - this.issues = element.getAttribute("issues"); - } + public String createAccessMode; + public String issues; + + public String getType() { + return "issuetracker"; + } + + @Override + public String stats() { + return this.issues + " issues"; + } + + public WebMediumConfig credentials() { + IssueTrackerConfig config = new IssueTrackerConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.createAccessMode = element.getAttribute("createAccessMode"); + this.issues = element.getAttribute("issues"); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java index 772b30a..cc4c7b1 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/LearningConfig.java @@ -27,96 +27,98 @@ import org.w3c.dom.Element; * DTO for XML voice config. */ public class LearningConfig extends Config { - - public String learningMode; - public String learningRate; - public String correctionMode; - public boolean enableComprehension; - public boolean enableEmoting; - public boolean enableEmotions; - public boolean enableConsciousness; - public boolean enableWiktionary; - public boolean enableResponseMatch; - public boolean learnGrammar; - public boolean synthesizeResponse; - public boolean fixFormulaCase; - public boolean checkExactMatchFirst; - public int scriptTimeout; - public int responseMatchTimeout; - public String conversationMatchPercentage; - public String discussionMatchPercentage; - - public void parseXML(Element element) { - super.parseXML(element); - - this.learningMode = element.getAttribute("learningMode"); - this.learningRate = element.getAttribute("learningRate"); - this.correctionMode = element.getAttribute("correctionMode"); - this.enableComprehension = Boolean.valueOf(element.getAttribute("enableComprehension")); - this.enableEmoting = Boolean.valueOf(element.getAttribute("enableEmoting")); - this.enableEmotions = Boolean.valueOf(element.getAttribute("enableEmotions")); - this.enableConsciousness = Boolean.valueOf(element.getAttribute("enableConsciousness")); - this.enableWiktionary = Boolean.valueOf(element.getAttribute("enableWiktionary")); - this.enableResponseMatch = Boolean.valueOf(element.getAttribute("enableResponseMatch")); - this.learnGrammar = Boolean.valueOf(element.getAttribute("learnGrammar")); - this.synthesizeResponse = Boolean.valueOf(element.getAttribute("synthesizeResponse")); - this.fixFormulaCase = Boolean.valueOf(element.getAttribute("fixFormulaCase")); - this.checkExactMatchFirst = Boolean.valueOf(element.getAttribute("checkExactMatchFirst")); - String value = element.getAttribute("scriptTimeout"); - if (value != null && value.length() > 0) { - try { - this.scriptTimeout = Integer.valueOf(value); - } catch (Exception ignore) {} - } - value = element.getAttribute("responseMatchTimeout"); - if (value != null && value.length() > 0) { - try { - this.responseMatchTimeout = Integer.valueOf(value); - } catch (Exception ignore) {} - } - this.conversationMatchPercentage = element.getAttribute("conversationMatchPercentage"); - this.discussionMatchPercentage = element.getAttribute("discussionMatchPercentage"); - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(" 0) { - writer.write(" conversationMatchPercentage=\"" + this.conversationMatchPercentage + "\""); - } - if (this.discussionMatchPercentage != null && this.discussionMatchPercentage.length() > 0) { - writer.write(" discussionMatchPercentage=\"" + this.discussionMatchPercentage + "\""); - } - if (this.learningRate != null && this.learningRate.length() > 0) { - writer.write(" learningRate=\"" + this.learningRate + "\""); - } - - writer.write("/>"); - return writer.toString(); - } + public void parseXML(Element element) { + super.parseXML(element); + + this.learningMode = element.getAttribute("learningMode"); + this.learningRate = element.getAttribute("learningRate"); + this.correctionMode = element.getAttribute("correctionMode"); + this.enableComprehension = Boolean.valueOf(element.getAttribute("enableComprehension")); + this.enableEmoting = Boolean.valueOf(element.getAttribute("enableEmoting")); + this.enableEmotions = Boolean.valueOf(element.getAttribute("enableEmotions")); + this.enableConsciousness = Boolean.valueOf(element.getAttribute("enableConsciousness")); + this.enableWiktionary = Boolean.valueOf(element.getAttribute("enableWiktionary")); + this.enableResponseMatch = Boolean.valueOf(element.getAttribute("enableResponseMatch")); + this.learnGrammar = Boolean.valueOf(element.getAttribute("learnGrammar")); + this.synthesizeResponse = Boolean.valueOf(element.getAttribute("synthesizeResponse")); + this.fixFormulaCase = Boolean.valueOf(element.getAttribute("fixFormulaCase")); + this.checkExactMatchFirst = Boolean.valueOf(element.getAttribute("checkExactMatchFirst")); + String value = element.getAttribute("scriptTimeout"); + if (value != null && value.length() > 0) { + try { + this.scriptTimeout = Integer.valueOf(value); + } catch (Exception ignore) { + } + } + value = element.getAttribute("responseMatchTimeout"); + if (value != null && value.length() > 0) { + try { + this.responseMatchTimeout = Integer.valueOf(value); + } catch (Exception ignore) { + } + } + this.conversationMatchPercentage = element.getAttribute("conversationMatchPercentage"); + this.discussionMatchPercentage = element.getAttribute("discussionMatchPercentage"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(" 0) { + writer.write(" conversationMatchPercentage=\"" + this.conversationMatchPercentage + "\""); + } + if (this.discussionMatchPercentage != null && this.discussionMatchPercentage.length() > 0) { + writer.write(" discussionMatchPercentage=\"" + this.discussionMatchPercentage + "\""); + } + if (this.learningRate != null && this.learningRate.length() > 0) { + writer.write(" learningRate=\"" + this.learningRate + "\""); + } + + writer.write("/>"); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java index 3f74f81..fa8d0df 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/MediaConfig.java @@ -27,45 +27,45 @@ import org.w3c.dom.Element; * DTO for XML media config. */ public class MediaConfig extends Config { - public long id; - public String name; - public String types; - public String file; - public String key; - - public void parseXML(Element element) { - super.parseXML(element); - - this.id = Long.valueOf(element.getAttribute("id")); - this.name = element.getAttribute("name"); - this.types = element.getAttribute("type"); - this.file = element.getAttribute("file"); - this.key = element.getAttribute("key"); - } + public long id; + public String name; + public String types; + public String file; + public String key; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + this.id = Long.valueOf(element.getAttribute("id")); + this.name = element.getAttribute("name"); + this.types = element.getAttribute("type"); + this.file = element.getAttribute("file"); + this.key = element.getAttribute("key"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java index 8984f85..0449961 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/OfflineTemplateConfig.java @@ -15,87 +15,88 @@ * limitations under the License. * ******************************************************************************/ - + package org.botlibre.sdk.config; public class OfflineTemplateConfig { - private int imageId; - private int id_; - private String id; - private String title; - private String dec; - - public OfflineTemplateConfig(){ + private int imageId; + private int id_; + private String id; + private String title; + private String dec; + + public OfflineTemplateConfig() { + + } + + public OfflineTemplateConfig(int imageId, String title, String dec, String id) { + this.setImageId(imageId); + this.setTitle(title); + this.setDec(dec); + this.setId(id); + } + + public OfflineTemplateConfig(int imageId, String title, String dec, String id, int id_) { + this.setImageId(imageId); + this.setTitle(title); + this.setDec(dec); + this.setId(id); + this.setId_(id_); + } + + public int getImageId() { + return imageId; + } - } - - public OfflineTemplateConfig(int imageId, String title, String dec, String id){ - this.setImageId(imageId); - this.setTitle(title); - this.setDec(dec); - this.setId(id); - } - public OfflineTemplateConfig(int imageId, String title, String dec, String id,int id_){ - this.setImageId(imageId); - this.setTitle(title); - this.setDec(dec); - this.setId(id); - this.setId_(id_); - } - public int getImageId() { - return imageId; - } + public void setImageId(int imageId) { + this.imageId = imageId; + } - public void setImageId(int imageId) { - this.imageId = imageId; - } + public String getTitle() { + return title; + } - public String getTitle() { - return title; - } + public void setTitle(String title) { + this.title = title; + } + @Override + public String toString() { + return title + "\n" + dec; - public void setTitle(String title) { - this.title = title; - } - - @Override - public String toString(){ - return title + "\n" + dec; - - } + } - public String getDec() { - return dec; - } + public String getDec() { + return dec; + } - public void setDec(String dec) { - this.dec = dec; - } + public void setDec(String dec) { + this.dec = dec; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public int getId_() { - return id_; - } + public int getId_() { + return id_; + } - public void setId_(int id_) { - this.id_ = id_; - } + public void setId_(int id_) { + this.id_ = id_; + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java index bf74806..36022bc 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java @@ -31,175 +31,175 @@ import org.w3c.dom.Node; /** * DTO for XML response config. */ -public class ResponseConfig extends Config { - public String questionId; - public String responseId; - public String question; - public String response; - public String previous; - public String onRepeat; - public String label; - public String topic; - public String keywords; - public String required; - public String emotions; - public String actions; - public String poses; - public boolean noRepeat; - public boolean requirePrevious; - public boolean requireTopic; - public boolean flagged; - public String correctness; - public String command; +public class ResponseConfig extends Config { + public String questionId; + public String responseId; + public String question; + public String response; + public String previous; + public String onRepeat; + public String label; + public String topic; + public String keywords; + public String required; + public String emotions; + public String actions; + public String poses; + public boolean noRepeat; + public boolean requirePrevious; + public boolean requireTopic; + public boolean flagged; + public String correctness; + public String command; - public ResponseConfig() { - - } - - public boolean equals(Object object) { - if (this == object) { - return true; - } - if ((object instanceof ResponseConfig) && (this.responseId != null) && !this.responseId.isEmpty() - && this.responseId.equals(((ResponseConfig)object).responseId)) { - if (((this.questionId == null) || this.questionId.isEmpty()) - && (((ResponseConfig)object).questionId == null) || ((ResponseConfig)object).questionId.isEmpty()) { - return true; - } - if ((this.questionId != null) && !this.questionId.isEmpty() - && this.questionId.equals(((ResponseConfig)object).questionId)) { - return true; - } - } - return super.equals(object); - } + public ResponseConfig() { - @Override - public int hashCode() { - return Objects.hash(questionId, responseId, question, response, previous, onRepeat, label, topic, keywords, required, emotions, actions, poses, noRepeat, requirePrevious, requireTopic, flagged, correctness, command); - } + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + public boolean equals(Object object) { + if (this == object) { + return true; + } + if ((object instanceof ResponseConfig) && (this.responseId != null) && !this.responseId.isEmpty() + && this.responseId.equals(((ResponseConfig) object).responseId)) { + if (((this.questionId == null) || this.questionId.isEmpty()) + && (((ResponseConfig) object).questionId == null) || ((ResponseConfig) object).questionId.isEmpty()) { + return true; + } + if ((this.questionId != null) && !this.questionId.isEmpty() + && this.questionId.equals(((ResponseConfig) object).questionId)) { + return true; + } + } + return super.equals(object); + } - public void writeXML(StringWriter writer) { - writer.write(""); - if (this.question != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.question)); - writer.write(""); - } - if (this.response != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.response)); - writer.write(""); - } - if (this.previous != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.previous)); - writer.write(""); - } - if (this.onRepeat != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.onRepeat)); - writer.write(""); - } - if (this.command != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.command)); - writer.write(""); - } - writer.write(""); - } - - public void parseXML(Element element) { - this.questionId = element.getAttribute("questionId"); - this.responseId = element.getAttribute("responseId"); - this.label = element.getAttribute("label"); - this.topic = element.getAttribute("topic"); - this.keywords = element.getAttribute("keywords"); - this.required = element.getAttribute("required"); - this.emotions = element.getAttribute("emotions"); - this.actions = element.getAttribute("actions"); - this.poses = element.getAttribute("poses"); - this.type = element.getAttribute("type"); - this.correctness = element.getAttribute("correctness"); - if (element.getAttribute("noRepeat") != null) { - this.noRepeat = Boolean.valueOf(element.getAttribute("noRepeat")); - } - if (element.getAttribute("flagged") != null) { - this.flagged = Boolean.valueOf(element.getAttribute("flagged")); - } - if (element.getAttribute("requireTopic") != null) { - this.requireTopic = Boolean.valueOf(element.getAttribute("requireTopic")); - } - if (element.getAttribute("requirePrevious") != null) { - this.requirePrevious = Boolean.valueOf(element.getAttribute("requirePrevious")); - } - - Node node = element.getElementsByTagName("question").item(0); - if (node != null) { - this.question = node.getTextContent(); - } - node = element.getElementsByTagName("response").item(0); - if (node != null) { - this.response = node.getTextContent(); - } - node = element.getElementsByTagName("command").item(0); - if (node != null) { - this.command = node.getTextContent(); - this.command = this.command.replace(""", "\""); - } - } - - public ZSONObject getCommand(){ - if (this.command == null || this.command.equals("")){ - return null; - } - try { - return new ZSONObject(); - } catch (ZSONException e) { - e.printStackTrace(); - } - return null; - } + @Override + public int hashCode() { + return Objects.hash(questionId, responseId, question, response, previous, onRepeat, label, topic, keywords, required, emotions, actions, poses, noRepeat, requirePrevious, requireTopic, flagged, correctness, command); + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writeXML(writer); + return writer.toString(); + } + + public void writeXML(StringWriter writer) { + writer.write(""); + if (this.question != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.question)); + writer.write(""); + } + if (this.response != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.response)); + writer.write(""); + } + if (this.previous != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.previous)); + writer.write(""); + } + if (this.onRepeat != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.onRepeat)); + writer.write(""); + } + if (this.command != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.command)); + writer.write(""); + } + writer.write(""); + } + + public void parseXML(Element element) { + this.questionId = element.getAttribute("questionId"); + this.responseId = element.getAttribute("responseId"); + this.label = element.getAttribute("label"); + this.topic = element.getAttribute("topic"); + this.keywords = element.getAttribute("keywords"); + this.required = element.getAttribute("required"); + this.emotions = element.getAttribute("emotions"); + this.actions = element.getAttribute("actions"); + this.poses = element.getAttribute("poses"); + this.type = element.getAttribute("type"); + this.correctness = element.getAttribute("correctness"); + if (element.getAttribute("noRepeat") != null) { + this.noRepeat = Boolean.valueOf(element.getAttribute("noRepeat")); + } + if (element.getAttribute("flagged") != null) { + this.flagged = Boolean.valueOf(element.getAttribute("flagged")); + } + if (element.getAttribute("requireTopic") != null) { + this.requireTopic = Boolean.valueOf(element.getAttribute("requireTopic")); + } + if (element.getAttribute("requirePrevious") != null) { + this.requirePrevious = Boolean.valueOf(element.getAttribute("requirePrevious")); + } + + Node node = element.getElementsByTagName("question").item(0); + if (node != null) { + this.question = node.getTextContent(); + } + node = element.getElementsByTagName("response").item(0); + if (node != null) { + this.response = node.getTextContent(); + } + node = element.getElementsByTagName("command").item(0); + if (node != null) { + this.command = node.getTextContent(); + this.command = this.command.replace(""", "\""); + } + } + + public ZSONObject getCommand() { + if (this.command == null || this.command.equals("")) { + return null; + } + try { + return new ZSONObject(); + } catch (ZSONException e) { + e.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java index c8bddf6..64b83bf 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ResponseSearchConfig.java @@ -24,34 +24,34 @@ import java.io.StringWriter; * DTO for XML response search options. */ public class ResponseSearchConfig extends Config { - public String responseType; - public String inputType; - public String filter; - public String duration; - public String restrict; - public String page; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String responseType; + public String inputType; + public String filter; + public String duration; + public String restrict; + public String page; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java index a536caf..d7b0c0c 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ScriptConfig.java @@ -21,45 +21,44 @@ import java.io.StringWriter; import org.w3c.dom.Element; public class ScriptConfig extends WebMediumConfig { - public String language; - public String version; + public String language; + public String version; - public String getType() { - return "script"; - } + public String getType() { + return "script"; + } - public WebMediumConfig credentials() { - ScriptConfig config = new ScriptConfig(); - config.id = this.id; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - return writer.toString(); - } - - public void parseXML(Element element){ - super.parseXML(element); - this.language = element.getAttribute("language"); - this.version = element.getAttribute("version"); - } - - @Override - public String toString() { - return this.name; - } - + public WebMediumConfig credentials() { + ScriptConfig config = new ScriptConfig(); + config.id = this.id; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + return writer.toString(); + } + + public void parseXML(Element element) { + super.parseXML(element); + this.language = element.getAttribute("language"); + this.version = element.getAttribute("version"); + } + + @Override + public String toString() { + return this.name; + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java index b90dfe5..8ff3cdc 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java @@ -42,87 +42,86 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -public class ScriptSourceConfig extends Config{ - public String id; - public String creationDate; - public String updateDate; - public boolean version; - public String versionName; - public String creator; - public String source; - - public ScriptSourceConfig credentials() { - ScriptSourceConfig config = new ScriptSourceConfig(); - config.creator = this.creator; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.source != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.source)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - - public void parseXML(Element element){ - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.updateDate = element.getAttribute("updateDate"); - this.version = Boolean.valueOf(element.getAttribute("version")); - this.versionName = element.getAttribute("versionName"); - this.creator = element.getAttribute("creator"); - - Node node = element.getElementsByTagName("source").item(0); - if (node != null) { - this.source = node.getTextContent(); - } - } - - public String getNextVersion() { - if (this.source == null) { - return "0.1"; - } - - String version = this.source; - int index = version.lastIndexOf('.'); - if (index != -1) { - String major = version.substring(0, index); - String minor = version.substring(index + 1, version.length()); - try { - int value = Integer.valueOf(minor); - version = major + "." + (value + 1); - } - catch (NumberFormatException ignore) { - } - } - return version; - } +public class ScriptSourceConfig extends Config { + public String id; + public String creationDate; + public String updateDate; + public boolean version; + public String versionName; + public String creator; + public String source; + + public ScriptSourceConfig credentials() { + ScriptSourceConfig config = new ScriptSourceConfig(); + config.creator = this.creator; + return config; + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.source != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.source)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.creationDate = element.getAttribute("creationDate"); + this.updateDate = element.getAttribute("updateDate"); + this.version = Boolean.valueOf(element.getAttribute("version")); + this.versionName = element.getAttribute("versionName"); + this.creator = element.getAttribute("creator"); + + Node node = element.getElementsByTagName("source").item(0); + if (node != null) { + this.source = node.getTextContent(); + } + } + + public String getNextVersion() { + if (this.source == null) { + return "0.1"; + } + + String version = this.source; + int index = version.lastIndexOf('.'); + if (index != -1) { + String major = version.substring(0, index); + String minor = version.substring(index + 1, version.length()); + try { + int value = Integer.valueOf(minor); + version = major + "." + (value + 1); + } catch (NumberFormatException ignore) { + } + } + return version; + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/Speech.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/Speech.java index 63a6d47..9694370 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/Speech.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/Speech.java @@ -25,24 +25,24 @@ import java.io.StringWriter; * The object takes a message text, and a voice. */ public class Speech extends Config { - public String text; - public String voice; - public String mod; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + public String text; + public String voice; + public String mod; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java index 0bb5194..cd80f18 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/TrainingConfig.java @@ -23,38 +23,37 @@ import org.botlibre.util.Utils; import java.io.StringWriter; - /** * DTO for XML training config. */ -public class TrainingConfig extends Config { - public String operation; - public String question; - public String response; - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.question != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.question)); - writer.write(""); - } - if (this.response != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.response)); - writer.write(""); - } - - writer.write(""); - return writer.toString(); - } +public class TrainingConfig extends Config { + public String operation; + public String question; + public String response; + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.question != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.question)); + writer.write(""); + } + if (this.response != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.response)); + writer.write(""); + } + + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java index b68c510..5961d5f 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserAdminConfig.java @@ -26,31 +26,31 @@ import org.w3c.dom.Element; /** * DTO for XML user admin config. */ -public class UserAdminConfig extends Config { - public String operation; - public String operationUser; - - public void parseXML(Element element) { - super.parseXML(element); - - this.operation = element.getAttribute("operation"); - this.operationUser = element.getAttribute("operationUser"); - } - - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } +public class UserAdminConfig extends Config { + public String operation; + public String operationUser; + + public void parseXML(Element element) { + super.parseXML(element); + + this.operation = element.getAttribute("operation"); + this.operationUser = element.getAttribute("operationUser"); + } + + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java index 426ea2a..cfe5504 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserConfig.java @@ -34,150 +34,150 @@ import org.botlibre.sdk.util.Utils; * DTO for XML user creation config. */ public class UserConfig extends Config { - public String password; - public String newPassword; - public String hint; - public String name; - public boolean showName; - public String email; - public String website; - public String bio; - public boolean over18; - public String avatar; - - public String connects; - public String bots; - public String posts; - public String messages; - public String forums; - public String scripts; - public String graphics; - public String avatars; - public String domains; - public String channels; - - public String joined; - public String lastConnect; - public String types; - public boolean isFlagged; - public String flaggedReason; - - public String displayJoined() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(joined); - return Utils.displayDate(date); - } catch (Exception exception) { - return joined; - } - } - - public String displayLastConnect() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(lastConnect); - return Utils.displayTimestamp(date); - } catch (Exception exception) { - return lastConnect; - } - } - - public void addCredentials(SDKConnection connection) { - this.application = connection.getCredentials().getApplicationId(); - if (connection.getDomain() != null) { - this.domain = connection.getDomain().id; - } - } - - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (!(object instanceof UserConfig)) { - return false; - } - return this.user != null && this.user.equals(((UserConfig)object).user); - } - - @Override - public int hashCode() { - return Objects.hash(password, newPassword, hint, name, showName, email, website, bio, over18, avatar, connects, bots, posts, messages, forums, scripts, graphics, avatars, domains, channels, joined, lastConnect, type, isFlagged, flaggedReason); - } - - public void parseXML(Element element) { - this.user = element.getAttribute("user"); - this.name = element.getAttribute("name"); - this.showName = Boolean.valueOf(element.getAttribute("showName")); - this.token = element.getAttribute("token"); - this.email = element.getAttribute("email"); - this.hint = element.getAttribute("hint"); - this.website = element.getAttribute("website"); - this.connects = element.getAttribute("connects"); - this.bots = element.getAttribute("bots"); - this.posts = element.getAttribute("posts"); - this.messages = element.getAttribute("messages"); - this.forums = element.getAttribute("forums"); - this.channels = element.getAttribute("channels"); - this.avatars = element.getAttribute("avatars"); - this.scripts = element.getAttribute("scripts"); - this.graphics = element.getAttribute("graphics"); - this.domains = element.getAttribute("domains"); - this.joined = element.getAttribute("joined"); - this.lastConnect = element.getAttribute("lastConnect"); - this.types = element.getAttribute("type"); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - - Node node = element.getElementsByTagName("bio").item(0); - if (node != null) { - this.bio = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - - if (this.bio != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.bio)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } - + public String password; + public String newPassword; + public String hint; + public String name; + public boolean showName; + public String email; + public String website; + public String bio; + public boolean over18; + public String avatar; + + public String connects; + public String bots; + public String posts; + public String messages; + public String forums; + public String scripts; + public String graphics; + public String avatars; + public String domains; + public String channels; + + public String joined; + public String lastConnect; + public String types; + public boolean isFlagged; + public String flaggedReason; + + public String displayJoined() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(joined); + return Utils.displayDate(date); + } catch (Exception exception) { + return joined; + } + } + + public String displayLastConnect() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(lastConnect); + return Utils.displayTimestamp(date); + } catch (Exception exception) { + return lastConnect; + } + } + + public void addCredentials(SDKConnection connection) { + this.application = connection.getCredentials().getApplicationId(); + if (connection.getDomain() != null) { + this.domain = connection.getDomain().id; + } + } + + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (!(object instanceof UserConfig)) { + return false; + } + return this.user != null && this.user.equals(((UserConfig) object).user); + } + + @Override + public int hashCode() { + return Objects.hash(password, newPassword, hint, name, showName, email, website, bio, over18, avatar, connects, bots, posts, messages, forums, scripts, graphics, avatars, domains, channels, joined, lastConnect, type, isFlagged, flaggedReason); + } + + public void parseXML(Element element) { + this.user = element.getAttribute("user"); + this.name = element.getAttribute("name"); + this.showName = Boolean.valueOf(element.getAttribute("showName")); + this.token = element.getAttribute("token"); + this.email = element.getAttribute("email"); + this.hint = element.getAttribute("hint"); + this.website = element.getAttribute("website"); + this.connects = element.getAttribute("connects"); + this.bots = element.getAttribute("bots"); + this.posts = element.getAttribute("posts"); + this.messages = element.getAttribute("messages"); + this.forums = element.getAttribute("forums"); + this.channels = element.getAttribute("channels"); + this.avatars = element.getAttribute("avatars"); + this.scripts = element.getAttribute("scripts"); + this.graphics = element.getAttribute("graphics"); + this.domains = element.getAttribute("domains"); + this.joined = element.getAttribute("joined"); + this.lastConnect = element.getAttribute("lastConnect"); + this.types = element.getAttribute("type"); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + + Node node = element.getElementsByTagName("bio").item(0); + if (node != null) { + this.bio = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.bio != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.bio)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } + } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java index 61e47a6..9ba0857 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/UserMessageConfig.java @@ -29,72 +29,72 @@ import org.w3c.dom.Node; * DTO for XML content config. */ public class UserMessageConfig extends Config { - public String id; - public String creationDate; - public String owner; - public String creator; - public String target; - public String parent; - public String subject; - public String message; - - public void parseXML(Element element) { - super.parseXML(element); - - this.id = element.getAttribute("id"); - this.creationDate = element.getAttribute("creationDate"); - this.owner = element.getAttribute("owner"); - this.creator = element.getAttribute("creator"); - this.target = element.getAttribute("target"); - this.parent = element.getAttribute("parent"); - - Node node = element.getElementsByTagName("subject").item(0); - if (node != null) { - this.subject = node.getTextContent(); - } - node = element.getElementsByTagName("message").item(0); - if (node != null) { - this.message = node.getTextContent(); - } - } + public String id; + public String creationDate; + public String owner; + public String creator; + public String target; + public String parent; + public String subject; + public String message; - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); + Node node = element.getElementsByTagName("subject").item(0); + if (node != null) { + this.subject = node.getTextContent(); + } + node = element.getElementsByTagName("message").item(0); + if (node != null) { + this.message = node.getTextContent(); + } + } - if (this.subject != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.subject)); - writer.write(""); - } - if (this.message != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.message)); - writer.write(""); - } - writer.write(""); - return writer.toString(); - } + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + + if (this.subject != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.subject)); + writer.write(""); + } + if (this.message != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.message)); + writer.write(""); + } + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java index 2c9a81f..78b63ce 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/VoiceConfig.java @@ -28,50 +28,50 @@ import org.w3c.dom.Element; */ public class VoiceConfig extends Config { - public String voice; - public boolean nativeVoice; - public String language; - public String pitch; - public String speechRate; - public String mod; - - public void parseXML(Element element) { - super.parseXML(element); + public String voice; + public boolean nativeVoice; + public String language; + public String pitch; + public String speechRate; + public String mod; - this.voice = element.getAttribute("voice"); - this.nativeVoice = Boolean.valueOf(element.getAttribute("nativeVoice")); - this.language = element.getAttribute("language"); - this.pitch = element.getAttribute("pitch"); - this.speechRate = element.getAttribute("speechRate"); - this.mod = element.getAttribute("mod"); - } + public void parseXML(Element element) { + super.parseXML(element); - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } + + public String toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java index 5fe3920..1807c1c 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/WebMediumConfig.java @@ -33,240 +33,240 @@ import org.w3c.dom.Node; */ public abstract class WebMediumConfig extends Config { - public String id; - public String name; - public boolean isAdmin; - public boolean isAdult; - public boolean isPrivate; - public boolean isHidden; - public String accessMode; - public boolean isFlagged; - public boolean isExternal; - public boolean isPaphus; - public boolean showAds = true; - public String forkAccessMode; - public String contentRating; - public String description; - public String details; - public String disclaimer; - public String website; - public String subdomain; - public String tags; - public String categories; - public String flaggedReason; - public String creator; - public String creationDate; - public String lastConnectedUser; - public String license; - public String avatar; - public String script; - public String graphic; - public int thumbsUp = 0; - public int thumbsDown = 0; - public String stars = "0"; - public String connects; - public String dailyConnects; - public String weeklyConnects; - public String monthlyConnects; - - public abstract String toXML(); - - public abstract String getType(); - - public abstract WebMediumConfig credentials(); - - public String stats() { - return ""; - } - - public boolean equals(Object object) { - if (object instanceof WebMediumConfig) { - if (this.id == null) { - return super.equals(object); - } - return this.id.equals(((WebMediumConfig)object).id); - } - return false; - } - - public String displayCreationDate() { - try { - SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - Date date = formater.parse(creationDate); - return Utils.displayDate(date); - } catch (Exception exception) { - return creationDate; - } - } - - public long getToken() { - long token = 0; - if ((this.token != null) && (this.token.equals(""))) { - token = Long.valueOf(this.token); - } - return token; - } + public String id; + public String name; + public boolean isAdmin; + public boolean isAdult; + public boolean isPrivate; + public boolean isHidden; + public String accessMode; + public boolean isFlagged; + public boolean isExternal; + public boolean isPaphus; + public boolean showAds = true; + public String forkAccessMode; + public String contentRating; + public String description; + public String details; + public String disclaimer; + public String website; + public String subdomain; + public String tags; + public String categories; + public String flaggedReason; + public String creator; + public String creationDate; + public String lastConnectedUser; + public String license; + public String avatar; + public String script; + public String graphic; + public int thumbsUp = 0; + public int thumbsDown = 0; + public String stars = "0"; + public String connects; + public String dailyConnects; + public String weeklyConnects; + public String monthlyConnects; - public void writeXML(StringWriter writer) { - writeCredentials(writer); - if (this.id != null) { - writer.write(" id=\"" + this.id + "\""); - } - if (this.name != null) { - writer.write(" name=\"" + this.name + "\""); - } - if (this.isPrivate) { - writer.write(" isPrivate=\"true\""); - } - if (this.isHidden) { - writer.write(" isHidden=\"true\""); - } - if (this.accessMode != null && !this.accessMode.equals("")) { - writer.write(" accessMode=\"" + this.accessMode + "\""); - } - if (this.contentRating != null && !this.contentRating.equals("")) { - writer.write(" contentRating=\"" + this.contentRating + "\""); - } - if (this.forkAccessMode != null && !this.forkAccessMode.equals("")) { - writer.write(" forkAccessMode=\"" + this.forkAccessMode + "\""); - } + public abstract String toXML(); - if (this.stars != null && !this.stars.equals("")) { - writer.write(" stars=\"" + this.stars + "\""); - } - if (this.isAdult) { - writer.write(" isAdult=\"true\""); - } - if (this.isFlagged) { - writer.write(" isFlagged=\"true\""); - } - if (this.isExternal) { - writer.write(" isExternal=\"true\""); - } - if (this.showAds) { - writer.write(" showAds=\"true\""); - } - writer.write(">"); - if (this.description != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.description)); - writer.write(""); - } - if (this.details != null) { - writer.write("
"); - writer.write(Utils.escapeHTML(this.details)); - writer.write("
"); - } - if (this.disclaimer != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.disclaimer)); - writer.write(""); - } - if (this.categories != null) { - writer.write(""); - writer.write(this.categories); - writer.write(""); - } - if (this.tags != null) { - writer.write(""); - writer.write(this.tags); - writer.write(""); - } - if (this.license != null) { - writer.write(""); - writer.write(this.license); - writer.write(""); - } - if (this.website != null) { - writer.write(""); - writer.write(this.website); - writer.write(""); - } - if (this.subdomain != null) { - writer.write(""); - writer.write(this.subdomain); - writer.write(""); - } - if (this.flaggedReason != null) { - writer.write(""); - writer.write(Utils.escapeHTML(this.flaggedReason)); - writer.write(""); - } - } - - public void parseXML(Element element) { - this.id = element.getAttribute("id"); - this.name = element.getAttribute("name"); - this.creationDate = element.getAttribute("creationDate"); - this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate")); - this.isHidden = Boolean.valueOf(element.getAttribute("isHidden")); - this.accessMode = element.getAttribute("accessMode"); - this.contentRating = element.getAttribute("contentRating"); - this.forkAccessMode = element.getAttribute("forkAccessMode"); - this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); - this.isAdult = Boolean.valueOf(element.getAttribute("isAdult")); - this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); - this.isExternal = Boolean.valueOf(element.getAttribute("isExternal")); - this.creator = element.getAttribute("creator"); - this.creationDate = element.getAttribute("creationDate"); - this.connects = element.getAttribute("connects"); - this.dailyConnects = element.getAttribute("dailyConnects"); - this.weeklyConnects = element.getAttribute("weeklyConnects"); - this.showAds = Boolean.valueOf(element.getAttribute("showAds")); - this.monthlyConnects = element.getAttribute("monthlyConnects"); - if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { - this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); - } - if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { - this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); - } - if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { - this.stars = element.getAttribute("stars"); - } - - Node node = element.getElementsByTagName("description").item(0); - if (node != null) { - this.description = node.getTextContent(); - } - node = element.getElementsByTagName("details").item(0); - if (node != null) { - this.details = node.getTextContent(); - } - node = element.getElementsByTagName("disclaimer").item(0); - if (node != null) { - this.disclaimer = node.getTextContent(); - } - node = element.getElementsByTagName("categories").item(0); - if (node != null) { - this.categories = node.getTextContent(); - } - node = element.getElementsByTagName("tags").item(0); - if (node != null) { - this.tags = node.getTextContent(); - } - node = element.getElementsByTagName("flaggedReason").item(0); - if (node != null) { - this.flaggedReason = node.getTextContent(); - } - node = element.getElementsByTagName("lastConnectedUser").item(0); - if (node != null) { - this.lastConnectedUser = node.getTextContent(); - } - node = element.getElementsByTagName("license").item(0); - if (node != null) { - this.license = node.getTextContent(); - } - node = element.getElementsByTagName("website").item(0); - if (node != null) { - this.website = node.getTextContent(); - } - node = element.getElementsByTagName("subdomain").item(0); - if (node != null) { - this.subdomain = node.getTextContent(); - } - node = element.getElementsByTagName("avatar").item(0); - if (node != null) { - this.avatar = node.getTextContent(); - } - } + public abstract String getType(); + + public abstract WebMediumConfig credentials(); + + public String stats() { + return ""; + } + + public boolean equals(Object object) { + if (object instanceof WebMediumConfig) { + if (this.id == null) { + return super.equals(object); + } + return this.id.equals(((WebMediumConfig) object).id); + } + return false; + } + + public String displayCreationDate() { + try { + SimpleDateFormat formater = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + Date date = formater.parse(creationDate); + return Utils.displayDate(date); + } catch (Exception exception) { + return creationDate; + } + } + + public long getToken() { + long token = 0; + if ((this.token != null) && (this.token.equals(""))) { + token = Long.valueOf(this.token); + } + return token; + } + + public void writeXML(StringWriter writer) { + writeCredentials(writer); + if (this.id != null) { + writer.write(" id=\"" + this.id + "\""); + } + if (this.name != null) { + writer.write(" name=\"" + this.name + "\""); + } + if (this.isPrivate) { + writer.write(" isPrivate=\"true\""); + } + if (this.isHidden) { + writer.write(" isHidden=\"true\""); + } + if (this.accessMode != null && !this.accessMode.equals("")) { + writer.write(" accessMode=\"" + this.accessMode + "\""); + } + if (this.contentRating != null && !this.contentRating.equals("")) { + writer.write(" contentRating=\"" + this.contentRating + "\""); + } + if (this.forkAccessMode != null && !this.forkAccessMode.equals("")) { + writer.write(" forkAccessMode=\"" + this.forkAccessMode + "\""); + } + + if (this.stars != null && !this.stars.equals("")) { + writer.write(" stars=\"" + this.stars + "\""); + } + if (this.isAdult) { + writer.write(" isAdult=\"true\""); + } + if (this.isFlagged) { + writer.write(" isFlagged=\"true\""); + } + if (this.isExternal) { + writer.write(" isExternal=\"true\""); + } + if (this.showAds) { + writer.write(" showAds=\"true\""); + } + writer.write(">"); + if (this.description != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.description)); + writer.write(""); + } + if (this.details != null) { + writer.write("
"); + writer.write(Utils.escapeHTML(this.details)); + writer.write("
"); + } + if (this.disclaimer != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.disclaimer)); + writer.write(""); + } + if (this.categories != null) { + writer.write(""); + writer.write(this.categories); + writer.write(""); + } + if (this.tags != null) { + writer.write(""); + writer.write(this.tags); + writer.write(""); + } + if (this.license != null) { + writer.write(""); + writer.write(this.license); + writer.write(""); + } + if (this.website != null) { + writer.write(""); + writer.write(this.website); + writer.write(""); + } + if (this.subdomain != null) { + writer.write(""); + writer.write(this.subdomain); + writer.write(""); + } + if (this.flaggedReason != null) { + writer.write(""); + writer.write(Utils.escapeHTML(this.flaggedReason)); + writer.write(""); + } + } + + public void parseXML(Element element) { + this.id = element.getAttribute("id"); + this.name = element.getAttribute("name"); + this.creationDate = element.getAttribute("creationDate"); + this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate")); + this.isHidden = Boolean.valueOf(element.getAttribute("isHidden")); + this.accessMode = element.getAttribute("accessMode"); + this.contentRating = element.getAttribute("contentRating"); + this.forkAccessMode = element.getAttribute("forkAccessMode"); + this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin")); + this.isAdult = Boolean.valueOf(element.getAttribute("isAdult")); + this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged")); + this.isExternal = Boolean.valueOf(element.getAttribute("isExternal")); + this.creator = element.getAttribute("creator"); + this.creationDate = element.getAttribute("creationDate"); + this.connects = element.getAttribute("connects"); + this.dailyConnects = element.getAttribute("dailyConnects"); + this.weeklyConnects = element.getAttribute("weeklyConnects"); + this.showAds = Boolean.valueOf(element.getAttribute("showAds")); + this.monthlyConnects = element.getAttribute("monthlyConnects"); + if (element.getAttribute("thumbsUp") != null && element.getAttribute("thumbsUp").trim().length() > 0) { + this.thumbsUp = Integer.valueOf(element.getAttribute("thumbsUp")); + } + if (element.getAttribute("thumbsDown") != null && element.getAttribute("thumbsDown").trim().length() > 0) { + this.thumbsDown = Integer.valueOf(element.getAttribute("thumbsDown")); + } + if (element.getAttribute("stars") != null && element.getAttribute("stars").trim().length() > 0) { + this.stars = element.getAttribute("stars"); + } + + Node node = element.getElementsByTagName("description").item(0); + if (node != null) { + this.description = node.getTextContent(); + } + node = element.getElementsByTagName("details").item(0); + if (node != null) { + this.details = node.getTextContent(); + } + node = element.getElementsByTagName("disclaimer").item(0); + if (node != null) { + this.disclaimer = node.getTextContent(); + } + node = element.getElementsByTagName("categories").item(0); + if (node != null) { + this.categories = node.getTextContent(); + } + node = element.getElementsByTagName("tags").item(0); + if (node != null) { + this.tags = node.getTextContent(); + } + node = element.getElementsByTagName("flaggedReason").item(0); + if (node != null) { + this.flaggedReason = node.getTextContent(); + } + node = element.getElementsByTagName("lastConnectedUser").item(0); + if (node != null) { + this.lastConnectedUser = node.getTextContent(); + } + node = element.getElementsByTagName("license").item(0); + if (node != null) { + this.license = node.getTextContent(); + } + node = element.getElementsByTagName("website").item(0); + if (node != null) { + this.website = node.getTextContent(); + } + node = element.getElementsByTagName("subdomain").item(0); + if (node != null) { + this.subdomain = node.getTextContent(); + } + node = element.getElementsByTagName("avatar").item(0); + if (node != null) { + this.avatar = node.getTextContent(); + } + } } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/util/TextStream.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/TextStream.java index d0382e6..138290d 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/util/TextStream.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/TextStream.java @@ -29,630 +29,630 @@ import java.util.Set; */ public class TextStream { - public static final String WHITESPACE =" \t\n\r\f"; - public static final String HTTP =" \t\n\r\f\""; - public static final String TOKENS =" \t\n\r\f.,:;!()?[]{}+=^&*\"`~|/\\<>"; - public static final String TERMINATORS =".?!。"; - private static final Set ABBREVIATIONS = new HashSet(Arrays.asList(new String[]{"mr","ms", "mrs", "dr", "inc", "sr", "jr", "st"})); - public static Set IGNORABLE = new HashSet(Arrays.asList(new String[]{"'","`", "\"", ","})); - - /** - * The text being streamed. - */ - protected String text; - - /** - * The current stream index into the text. - */ - protected int index; - - public TextStream(String text) { - this.index = 0; - this.text = text; - } - - public void reset() { - this.index = 0; - } - - public char last() { - if (this.index <= 1) { - return (char)0; - } - return this.text.charAt(this.index - 2); - } - - public char current() { - if (this.index <= 0) { - return (char)0; - } - return this.text.charAt(this.index - 1); - } - - public char peekPrevious() { - if (this.index <= 1) { - return (char)0; - } - return this.text.charAt(this.index - 2); - } - - public char peek() { - if (atEnd()) { - return (char)-1; - } - return this.text.charAt(this.index); - } - - public int peekCodePoint() { - if (atEnd()) { - return (int)-1; - } - return this.text.codePointAt(this.index); - } - - public char next() { - if (this.index >= this.text.length()) { - return (char)-1; - } - char next = this.text.charAt(this.index); - this.index++; - return next; - } - - public char previous() { - this.index--; - char previous = current(); - return previous; - } - - public void skip() { - if (this.index >= this.text.length()) { - return; - } - this.index++; - } - - public void skip(int count) { - this.index = Math.min(this.index + count, this.text.length()); - } - - public void backup(int count) { - this.index = Math.max(this.index - count, 0); - } - - public void backup() { - this.index--; - } - - public String peek(int count) { - int start = this.index; - int end = Math.min(this.index + count, this.text.length()); - return this.text.substring(start, end); - } - - public String previous(int count) { - int end = this.index - 2; - if (end <= 0) { - return ""; - } - int start = Math.max(end - count, 0); - return this.text.substring(start, end); - } - - public String next(int count) { - int start = this.index; - this.index = Math.min(this.index + count, this.text.length()); - return this.text.substring(start, this.index); - } - - public boolean atEnd() { - return this.index >= this.text.length(); - } - - public boolean atStart() { - return this.index == 0; - } - - public String upTo(char token) { - return upTo(token, false); - } - - public void skipTo(char token) { - skipTo(token, false); - } - - public String upToEnd() { - int start = this.index; - this.index = this.text.length(); - return this.text.substring(start, this.index); - } - - public String upTo(char token, boolean including) { - return upTo(token, including, false); - } - - public String upTo(char token, boolean including, boolean resetIfNotFound) { - int start = this.index; - boolean found = skipTo(token, including); - if (resetIfNotFound && !found) { - this.index = start; - return ""; - } - return this.text.substring(start, this.index); - } - - public boolean skipTo(char token, boolean including) { - boolean found = false; - while (!atEnd()) { - if (peek() == token) { - found = true; - break; - } - skip(); - } - if (found && including) { - skip(); - } - return found; - } - - public void backupTo(char token) { - backupTo(token, false); - } - - public void backupTo(char token, boolean including) { - boolean found = false; - while (this.index > 0) { - if (current() == token) { - found = true; - break; - } - backup(); - } - if (found && including) { - backup(); - } - } - - public String upToAny(String tokens) { - return upToAny(tokens, false); - } - - public String upToAny(String tokens, boolean including) { - int start = this.index; - skipToAny(tokens, including); - return this.text.substring(start, this.index); - } - - public void skipToAny(String tokens) { - skipToAny(tokens, false); - } - - public void skipToAny(String tokens, boolean including) { - boolean found = false; - while (!atEnd()) { - if (tokens.indexOf(peek()) != -1) { - found = true; - break; - } - skip(); - } - if (found && including) { - skip(); - } - } - - public String upToAll(String tokens) { - return upToAll(tokens, false); - } - - public String upToAll(String tokens, boolean including) { - return upToAll(tokens, including, false); - } - - public String upToAll(String tokens, boolean including, boolean resetIfNotFound) { - int start = this.index; - boolean found = skipToAll(tokens, including); - if (resetIfNotFound && !found) { - this.index = start; - return ""; - } - return this.text.substring(start, this.index); - } - - public void skipToAll(String tokens) { - skipToAll(tokens, false); - } - - public boolean skipToAll(String tokens, boolean including) { - int tokenIndex = 0; - boolean found = false; - while (!atEnd()) { - if (peek() == tokens.charAt(tokenIndex)) { - tokenIndex++; - if (tokenIndex == tokens.length()) { - found = true; - break; - } - } else { - tokenIndex = 0; - } - skip(); - } - if (found) { - if (including) { - skip(); - } else { - this.index = index - (tokens.length() - 1); - } - } - return found; - } - - public void backupToAll(String tokens) { - backupToAll(tokens, false); - } - - public void backupToAll(String tokens, boolean including) { - int tokenIndex = 1; - int length = tokens.length(); - boolean found = false; - while (this.index > 0) { - if (current() == tokens.charAt(length - tokenIndex)) { - if (tokenIndex == tokens.length()) { - found = true; - break; - } - tokenIndex++; - } else { - tokenIndex = 1; - } - backup(); - } - if (found) { - if (including) { - backup(); - } else { - this.index = index + (length - 1); - } - } - } - - public void backupToAny(String tokens) { - backupToAny(tokens, false); - } - - public void backupToAny(String tokens, boolean including) { - boolean found = false; - while (!atStart()) { - if (tokens.indexOf(peekPrevious()) != -1) { - found = true; - break; - } - backup(); - } - if (found && including) { - backup(); - } - } - - public String peekWord() { - int position = this.index; - String word = nextWord(); - this.index = position; - return word; - } - - public List allWords() { - List words = new ArrayList(); - while (!atEnd()) { - String word = nextWord(); - if (word != null) { - words.add(word); - } - } - return words; - } - - public List csv() { - List words = new ArrayList(); - skipWhitespace(); - while (!atEnd()) { - String word = upTo(','); - if (!atEnd()) { - skip(); - skipWhitespace(); - } - if ((word != null) && !word.trim().equals("")) { - words.add(word); - } - } - return words; - } - - public String peekPreviousWord() { - int original = this.index; - backupWhitespace(); - int start = this.index; - if (atStart()) { - return null; - } - char current = current(); - if ((TOKENS.indexOf(current) != -1) || (isWordSymbol(current))) { - previous(); - String word = String.valueOf(current); - this.index = original; - return word; - } - backupToAny(TOKENS); - String word = this.text.substring(Math.max(this.index - 1, 0), start); - this.index = original; - return word; - } - - public boolean isWordSymbol(char character) { - Character.UnicodeBlock block = Character.UnicodeBlock.of(character); - return ((block == Character.UnicodeBlock.HIRAGANA) - || (block == Character.UnicodeBlock.KATAKANA) - || (block == Character.UnicodeBlock.HANGUL_SYLLABLES) - || (block == Character.UnicodeBlock.HANGUL_JAMO)) - && !Character.isDigit(character); - } - - public String nextQuotes() { - if (atEnd()) { - return ""; - } - int start = this.index; - skipQuotes(); - int end = this.index - 1; - if (atEnd() && current() != '"') { - end = this.index; - } - String quotes = this.text.substring(start, end); - return quotes; - } - - public String nextQuotesExcludeDoubleQuote() { - String quotes = nextQuotes(); - if (quotes.contains("\"\"")) { - quotes = quotes.replace("\"\"", "\""); - } - return quotes; - } - - public void skipQuotes() { - if (atEnd()) { - return; - } - char next = next(); - char peek = peek(); - while (!atEnd() && ((next != '"') || (peek == '"'))) { - if ((next == '"') && (peek == '"')) { - skip(); - } - if (next == '{') { - skipBrackets(); - } - next = next(); - peek = peek(); - } - } - - public void skipBrackets() { - if (atEnd()) { - return; - } - char next = next(); - while (!atEnd() && (next != '}')) { - if (next == '"') { - skipQuotes(); - } - next = next(); - } - } - - public String nextWord() { - skipWhitespace(); - if (atEnd()) { - return null; - } - //int peek = peekCodePoint(); - char peek = peek(); - boolean isSign = (peek == '-') || (peek == '+'); - // Check for "1-1" vs "1 - -1" - if (isSign && !atStart()) { - backup(); - char previous = peek(); - if (Character.isLetterOrDigit(previous)) { - skip(); - skip(); - return String.valueOf(peek); - } - skip(); - } - if (isWordSymbol(peek) || (!Character.isLetterOrDigit(peek) && peek != '_' && peek != '@' && !isSign)) { - skip(); - Character.UnicodeBlock block = Character.UnicodeBlock.of(peek); - if (block == Character.UnicodeBlock.HIGH_SURROGATES) { - skip(); - return this.text.substring(this.index - 2, this.index); - } - return String.valueOf(peek); - } - // Check url. - if (peek == 'h') { - if (peek(7).equals("http://") || peek(8).equals("https://")) { - return upToAny(HTTP); - } - } - int start = this.index; - boolean wasDigit = Character.isDigit(peek); - skip(); - while (!atEnd()) { - //peek = peekCodePoint(); - peek = peek(); - boolean isDigit = Character.isDigit(peek); - if (isWordSymbol(peek)) { - break; - } - // "-1" is ok - if (isSign && !isDigit) { - break; - } else { - // Allow "1.1", "1,000", "ab-ba", "ab_ba" - if (!Character.isLetter(peek) && !isDigit && (peek != '_')) { - if (wasDigit) { - if ((peek != '.') && (peek != ',') && (peek != '@')) { - break; - } - } else { - if ((peek != '-') && (peek != '_') && (peek != '@') && (peek != '.')) { - break; - } - } - } - } - wasDigit = isDigit; - skip(); - // Could have been "1.", "1.a" - if ((((peek == '.') && !Character.isLetter(peek())) || (peek == ',')) && !Character.isDigit(peek())) { - backup(); - break; - } - isSign = false; - } - return this.text.substring(start, this.index); - } - - public void skipWord() { - skipWhitespace(); - if (atEnd()) { - return; - } - if (TOKENS.indexOf(peek()) != -1) { - skip(); - } - // Check url. - if (peek() == 'h') { - if (peek(7).equals("http://")) { - skipToAny(WHITESPACE); - } - } - skipToAny(TOKENS); - } - - public String nextSentence() { - skipWhitespace(); - if (atEnd()) { - return null; - } - int start = this.index; - skipToAny(TERMINATORS, true); - while (!atEnd()) { - char peek = peek(); - boolean done = WHITESPACE.indexOf(peek) != -1; - if (done) { - if (current() != '.') { - break; - } - backup(); - String word = peekPreviousWord(); - skip(); - if (ABBREVIATIONS.contains(word.toLowerCase()) - || ((word.length() == 1) && (Character.isUpperCase(word.charAt(0))))) { - done = false; - } else { - break; - } - } else if (isWordSymbol(peek)) { - break; - } - skipToAny(TERMINATORS, true); - } - return this.text.substring(start, this.index); - } - - public String nextWhitespace() { - int start = this.index; - while (!atEnd() && (WHITESPACE.indexOf(peek()) != -1)) { - skip(); - } - return this.text.substring(start, this.index); - } - - public boolean skipWhitespace() { - boolean found = false; - while (!atEnd() && (Character.isWhitespace(peek()))) { - skip(); - found = true; - } - return found; - } - - public void backupWhitespace() { - while (!atStart() && (WHITESPACE.indexOf(current()) != -1)) { - backup(); - } - } - - public String nextLine() { - return upToAll("\n", true); - } - - public String currentLine() { - int position = this.index; - backupToAll("\n"); - String line = nextLine(); - this.index = position; - return line; - } - - public int currentLineNumber() { - int position = this.index; - this.index = 0; - int count = 0; - int last = this.index; - while (this.index < position) { - skipLine(); - if (this.index < position) { - count++; - } - if (this.index == last) { - break; - } - last = this.index; - } - this.index = position; - return count + 1; - } - - public int currentLineColumn() { - int position = this.index; - backupToAll("\n"); - int column = position - this.index; - this.index = position; - return column + 1; - } - - public void skipLine() { - skipToAll("\n", true); - } - - public int getPosition() { - return index; - } - - public void setPosition(int index) { - this.index = index; - } - - public String getText() { - return text; - } - - public String toString() { - return peek(text.length()); - } - + public static final String WHITESPACE = " \t\n\r\f"; + public static final String HTTP = " \t\n\r\f\""; + public static final String TOKENS = " \t\n\r\f.,:;!()?[]{}+=^&*\"`~|/\\<>"; + public static final String TERMINATORS = ".?!。"; + private static final Set ABBREVIATIONS = new HashSet(Arrays.asList(new String[]{"mr", "ms", "mrs", "dr", "inc", "sr", "jr", "st"})); + public static Set IGNORABLE = new HashSet(Arrays.asList(new String[]{"'", "`", "\"", ","})); + + /** + * The text being streamed. + */ + protected String text; + + /** + * The current stream index into the text. + */ + protected int index; + + public TextStream(String text) { + this.index = 0; + this.text = text; + } + + public void reset() { + this.index = 0; + } + + public char last() { + if (this.index <= 1) { + return (char) 0; + } + return this.text.charAt(this.index - 2); + } + + public char current() { + if (this.index <= 0) { + return (char) 0; + } + return this.text.charAt(this.index - 1); + } + + public char peekPrevious() { + if (this.index <= 1) { + return (char) 0; + } + return this.text.charAt(this.index - 2); + } + + public char peek() { + if (atEnd()) { + return (char) -1; + } + return this.text.charAt(this.index); + } + + public int peekCodePoint() { + if (atEnd()) { + return (int) -1; + } + return this.text.codePointAt(this.index); + } + + public char next() { + if (this.index >= this.text.length()) { + return (char) -1; + } + char next = this.text.charAt(this.index); + this.index++; + return next; + } + + public char previous() { + this.index--; + char previous = current(); + return previous; + } + + public void skip() { + if (this.index >= this.text.length()) { + return; + } + this.index++; + } + + public void skip(int count) { + this.index = Math.min(this.index + count, this.text.length()); + } + + public void backup(int count) { + this.index = Math.max(this.index - count, 0); + } + + public void backup() { + this.index--; + } + + public String peek(int count) { + int start = this.index; + int end = Math.min(this.index + count, this.text.length()); + return this.text.substring(start, end); + } + + public String previous(int count) { + int end = this.index - 2; + if (end <= 0) { + return ""; + } + int start = Math.max(end - count, 0); + return this.text.substring(start, end); + } + + public String next(int count) { + int start = this.index; + this.index = Math.min(this.index + count, this.text.length()); + return this.text.substring(start, this.index); + } + + public boolean atEnd() { + return this.index >= this.text.length(); + } + + public boolean atStart() { + return this.index == 0; + } + + public String upTo(char token) { + return upTo(token, false); + } + + public void skipTo(char token) { + skipTo(token, false); + } + + public String upToEnd() { + int start = this.index; + this.index = this.text.length(); + return this.text.substring(start, this.index); + } + + public String upTo(char token, boolean including) { + return upTo(token, including, false); + } + + public String upTo(char token, boolean including, boolean resetIfNotFound) { + int start = this.index; + boolean found = skipTo(token, including); + if (resetIfNotFound && !found) { + this.index = start; + return ""; + } + return this.text.substring(start, this.index); + } + + public boolean skipTo(char token, boolean including) { + boolean found = false; + while (!atEnd()) { + if (peek() == token) { + found = true; + break; + } + skip(); + } + if (found && including) { + skip(); + } + return found; + } + + public void backupTo(char token) { + backupTo(token, false); + } + + public void backupTo(char token, boolean including) { + boolean found = false; + while (this.index > 0) { + if (current() == token) { + found = true; + break; + } + backup(); + } + if (found && including) { + backup(); + } + } + + public String upToAny(String tokens) { + return upToAny(tokens, false); + } + + public String upToAny(String tokens, boolean including) { + int start = this.index; + skipToAny(tokens, including); + return this.text.substring(start, this.index); + } + + public void skipToAny(String tokens) { + skipToAny(tokens, false); + } + + public void skipToAny(String tokens, boolean including) { + boolean found = false; + while (!atEnd()) { + if (tokens.indexOf(peek()) != -1) { + found = true; + break; + } + skip(); + } + if (found && including) { + skip(); + } + } + + public String upToAll(String tokens) { + return upToAll(tokens, false); + } + + public String upToAll(String tokens, boolean including) { + return upToAll(tokens, including, false); + } + + public String upToAll(String tokens, boolean including, boolean resetIfNotFound) { + int start = this.index; + boolean found = skipToAll(tokens, including); + if (resetIfNotFound && !found) { + this.index = start; + return ""; + } + return this.text.substring(start, this.index); + } + + public void skipToAll(String tokens) { + skipToAll(tokens, false); + } + + public boolean skipToAll(String tokens, boolean including) { + int tokenIndex = 0; + boolean found = false; + while (!atEnd()) { + if (peek() == tokens.charAt(tokenIndex)) { + tokenIndex++; + if (tokenIndex == tokens.length()) { + found = true; + break; + } + } else { + tokenIndex = 0; + } + skip(); + } + if (found) { + if (including) { + skip(); + } else { + this.index = index - (tokens.length() - 1); + } + } + return found; + } + + public void backupToAll(String tokens) { + backupToAll(tokens, false); + } + + public void backupToAll(String tokens, boolean including) { + int tokenIndex = 1; + int length = tokens.length(); + boolean found = false; + while (this.index > 0) { + if (current() == tokens.charAt(length - tokenIndex)) { + if (tokenIndex == tokens.length()) { + found = true; + break; + } + tokenIndex++; + } else { + tokenIndex = 1; + } + backup(); + } + if (found) { + if (including) { + backup(); + } else { + this.index = index + (length - 1); + } + } + } + + public void backupToAny(String tokens) { + backupToAny(tokens, false); + } + + public void backupToAny(String tokens, boolean including) { + boolean found = false; + while (!atStart()) { + if (tokens.indexOf(peekPrevious()) != -1) { + found = true; + break; + } + backup(); + } + if (found && including) { + backup(); + } + } + + public String peekWord() { + int position = this.index; + String word = nextWord(); + this.index = position; + return word; + } + + public List allWords() { + List words = new ArrayList(); + while (!atEnd()) { + String word = nextWord(); + if (word != null) { + words.add(word); + } + } + return words; + } + + public List csv() { + List words = new ArrayList(); + skipWhitespace(); + while (!atEnd()) { + String word = upTo(','); + if (!atEnd()) { + skip(); + skipWhitespace(); + } + if ((word != null) && !word.trim().equals("")) { + words.add(word); + } + } + return words; + } + + public String peekPreviousWord() { + int original = this.index; + backupWhitespace(); + int start = this.index; + if (atStart()) { + return null; + } + char current = current(); + if ((TOKENS.indexOf(current) != -1) || (isWordSymbol(current))) { + previous(); + String word = String.valueOf(current); + this.index = original; + return word; + } + backupToAny(TOKENS); + String word = this.text.substring(Math.max(this.index - 1, 0), start); + this.index = original; + return word; + } + + public boolean isWordSymbol(char character) { + Character.UnicodeBlock block = Character.UnicodeBlock.of(character); + return ((block == Character.UnicodeBlock.HIRAGANA) + || (block == Character.UnicodeBlock.KATAKANA) + || (block == Character.UnicodeBlock.HANGUL_SYLLABLES) + || (block == Character.UnicodeBlock.HANGUL_JAMO)) + && !Character.isDigit(character); + } + + public String nextQuotes() { + if (atEnd()) { + return ""; + } + int start = this.index; + skipQuotes(); + int end = this.index - 1; + if (atEnd() && current() != '"') { + end = this.index; + } + String quotes = this.text.substring(start, end); + return quotes; + } + + public String nextQuotesExcludeDoubleQuote() { + String quotes = nextQuotes(); + if (quotes.contains("\"\"")) { + quotes = quotes.replace("\"\"", "\""); + } + return quotes; + } + + public void skipQuotes() { + if (atEnd()) { + return; + } + char next = next(); + char peek = peek(); + while (!atEnd() && ((next != '"') || (peek == '"'))) { + if ((next == '"') && (peek == '"')) { + skip(); + } + if (next == '{') { + skipBrackets(); + } + next = next(); + peek = peek(); + } + } + + public void skipBrackets() { + if (atEnd()) { + return; + } + char next = next(); + while (!atEnd() && (next != '}')) { + if (next == '"') { + skipQuotes(); + } + next = next(); + } + } + + public String nextWord() { + skipWhitespace(); + if (atEnd()) { + return null; + } + //int peek = peekCodePoint(); + char peek = peek(); + boolean isSign = (peek == '-') || (peek == '+'); + // Check for "1-1" vs "1 - -1" + if (isSign && !atStart()) { + backup(); + char previous = peek(); + if (Character.isLetterOrDigit(previous)) { + skip(); + skip(); + return String.valueOf(peek); + } + skip(); + } + if (isWordSymbol(peek) || (!Character.isLetterOrDigit(peek) && peek != '_' && peek != '@' && !isSign)) { + skip(); + Character.UnicodeBlock block = Character.UnicodeBlock.of(peek); + if (block == Character.UnicodeBlock.HIGH_SURROGATES) { + skip(); + return this.text.substring(this.index - 2, this.index); + } + return String.valueOf(peek); + } + // Check url. + if (peek == 'h') { + if (peek(7).equals("http://") || peek(8).equals("https://")) { + return upToAny(HTTP); + } + } + int start = this.index; + boolean wasDigit = Character.isDigit(peek); + skip(); + while (!atEnd()) { + //peek = peekCodePoint(); + peek = peek(); + boolean isDigit = Character.isDigit(peek); + if (isWordSymbol(peek)) { + break; + } + // "-1" is ok + if (isSign && !isDigit) { + break; + } else { + // Allow "1.1", "1,000", "ab-ba", "ab_ba" + if (!Character.isLetter(peek) && !isDigit && (peek != '_')) { + if (wasDigit) { + if ((peek != '.') && (peek != ',') && (peek != '@')) { + break; + } + } else { + if ((peek != '-') && (peek != '_') && (peek != '@') && (peek != '.')) { + break; + } + } + } + } + wasDigit = isDigit; + skip(); + // Could have been "1.", "1.a" + if ((((peek == '.') && !Character.isLetter(peek())) || (peek == ',')) && !Character.isDigit(peek())) { + backup(); + break; + } + isSign = false; + } + return this.text.substring(start, this.index); + } + + public void skipWord() { + skipWhitespace(); + if (atEnd()) { + return; + } + if (TOKENS.indexOf(peek()) != -1) { + skip(); + } + // Check url. + if (peek() == 'h') { + if (peek(7).equals("http://")) { + skipToAny(WHITESPACE); + } + } + skipToAny(TOKENS); + } + + public String nextSentence() { + skipWhitespace(); + if (atEnd()) { + return null; + } + int start = this.index; + skipToAny(TERMINATORS, true); + while (!atEnd()) { + char peek = peek(); + boolean done = WHITESPACE.indexOf(peek) != -1; + if (done) { + if (current() != '.') { + break; + } + backup(); + String word = peekPreviousWord(); + skip(); + if (ABBREVIATIONS.contains(word.toLowerCase()) + || ((word.length() == 1) && (Character.isUpperCase(word.charAt(0))))) { + done = false; + } else { + break; + } + } else if (isWordSymbol(peek)) { + break; + } + skipToAny(TERMINATORS, true); + } + return this.text.substring(start, this.index); + } + + public String nextWhitespace() { + int start = this.index; + while (!atEnd() && (WHITESPACE.indexOf(peek()) != -1)) { + skip(); + } + return this.text.substring(start, this.index); + } + + public boolean skipWhitespace() { + boolean found = false; + while (!atEnd() && (Character.isWhitespace(peek()))) { + skip(); + found = true; + } + return found; + } + + public void backupWhitespace() { + while (!atStart() && (WHITESPACE.indexOf(current()) != -1)) { + backup(); + } + } + + public String nextLine() { + return upToAll("\n", true); + } + + public String currentLine() { + int position = this.index; + backupToAll("\n"); + String line = nextLine(); + this.index = position; + return line; + } + + public int currentLineNumber() { + int position = this.index; + this.index = 0; + int count = 0; + int last = this.index; + while (this.index < position) { + skipLine(); + if (this.index < position) { + count++; + } + if (this.index == last) { + break; + } + last = this.index; + } + this.index = position; + return count + 1; + } + + public int currentLineColumn() { + int position = this.index; + backupToAll("\n"); + int column = position - this.index; + this.index = position; + return column + 1; + } + + public void skipLine() { + skipToAll("\n", true); + } + + public int getPosition() { + return index; + } + + public void setPosition(int index) { + this.index = index; + } + + public String getText() { + return text; + } + + public String toString() { + return peek(text.length()); + } + } \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/util/Utils.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/Utils.java index c5aecf8..a734895 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/util/Utils.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/Utils.java @@ -38,267 +38,267 @@ import java.util.regex.Pattern; * Utility class. */ public class Utils { - private static final Random random = new Random(); - - private static Pattern httpRegex = Pattern.compile("\\b(?:https?|ftp|file):\\/\\/[a-z0-9-+&@#\\/%?=~_|!:,.;]*[a-z0-9-+&@#\\/%=~_|]", Pattern.CASE_INSENSITIVE); - private static Pattern wwwRegex = Pattern.compile("((www\\.)[^\\s]+)", Pattern.CASE_INSENSITIVE); - private static Pattern emailRegex = Pattern.compile("(([a-zA-Z0-9_\\-\\.]+)@[a-zA-Z_]+?(?:\\.[a-zA-Z]{2,6}))+", Pattern.CASE_INSENSITIVE); - - /** - * Replace links with HTML links. - * Includes http, www, images, video, audio, email address. - * - * @param text String - * @return String - */ - public static String linkHTML(String text) { - if (text == null || text.length() == 0) { - return ""; - } - boolean http = text.indexOf("http") != -1; - boolean www = text.indexOf("www.") != -1; - boolean email = text.indexOf("@") != -1; - if (!http && !www && !email) { - return text; - } - if (text.indexOf("<") != -1 && text.indexOf(">") != -1) { - return text; - } - if (http) { - Matcher matcher = httpRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String url = matcher.group(); - if (url.indexOf(".png") != -1 || url.indexOf(".jpg") != -1 || url.indexOf(".jpeg") != -1 || url.indexOf(".gif") != -1) { - url = ""; - } else if (url.indexOf(".mp4") != -1 || url.indexOf(".webm") != -1 || url.indexOf(".ogg") != -1) { - url = ""; - } else if (url.indexOf(".wav") != -1 || url.indexOf(".mp3") != -1) { - url = ""; - } else { - url = "" + url + ""; - } - matcher.appendReplacement(sb, url); - } - matcher.appendTail(sb); - text = sb.toString(); - } else if (www) { - Matcher matcher = wwwRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String url = matcher.group(); - matcher.appendReplacement(sb, "" + url + ""); - } - matcher.appendTail(sb); - text = sb.toString(); - } - - if (email) { - Matcher matcher = emailRegex.matcher(text); - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - String address = matcher.group(); - matcher.appendReplacement(sb, "" + address + ""); - } - matcher.appendTail(sb); - text = sb.toString(); - } - return text; - } - + private static final Random random = new Random(); - /** - * Replace reserved HTML character with their HTML escape codes. - * - * @param html String - * @return String - */ - public static String escapeHTML(String html) { - return html.replace("&", "&") - .replace("<", "<") - .replace(">", ">") - .replace("\"", """) - .replace("`", "`") - .replace("'", "'"); - } + private static Pattern httpRegex = Pattern.compile("\\b(?:https?|ftp|file):\\/\\/[a-z0-9-+&@#\\/%?=~_|!:,.;]*[a-z0-9-+&@#\\/%=~_|]", Pattern.CASE_INSENSITIVE); + private static Pattern wwwRegex = Pattern.compile("((www\\.)[^\\s]+)", Pattern.CASE_INSENSITIVE); + private static Pattern emailRegex = Pattern.compile("(([a-zA-Z0-9_\\-\\.]+)@[a-zA-Z_]+?(?:\\.[a-zA-Z]{2,6}))+", Pattern.CASE_INSENSITIVE); - /** - * Strip the HTML tags from the text. - * - * @param html String - * @return String - */ - public static String stripTags(String html) { - if (html == null) { - return ""; - } - String result = html; - if ((html.indexOf('<') != -1) && (html.indexOf('>') != -1)) { - StringWriter writer = new StringWriter(); - TextStream stream = new TextStream(html); - while (!stream.atEnd()) { - String text = stream.upTo('<'); - writer.write(text); - int position = stream.getPosition(); - stream.skip(); - String word = stream.nextWord(); - if (word != null) { - if (word.equals("p")) { - writer.write("\n\n"); - } else if (word.equals("br")) { - writer.write("\n"); - } else if (word.equals("div")) { - writer.write("\n"); - } - stream.skipTo('>'); - if (stream.atEnd()) { - stream.setPosition(position); - writer.write(stream.upToEnd()); - } else { - stream.skip(); - } - } - } - result = writer.toString(); - } - if (result.contains("&")) { - result = result.replace(""", "\""); - result = result.replace("`", "`"); - result = result.replace("'", "'"); - result = result.replace("@", "@"); - result = result.replace("=", "="); - result = result.replace("<", "<"); - result = result.replace(">", ">"); - } - return result; - } + /** + * Replace links with HTML links. + * Includes http, www, images, video, audio, email address. + * + * @param text String + * @return String + */ + public static String linkHTML(String text) { + if (text == null || text.length() == 0) { + return ""; + } + boolean http = text.indexOf("http") != -1; + boolean www = text.indexOf("www.") != -1; + boolean email = text.indexOf("@") != -1; + if (!http && !www && !email) { + return text; + } + if (text.indexOf("<") != -1 && text.indexOf(">") != -1) { + return text; + } + if (http) { + Matcher matcher = httpRegex.matcher(text); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String url = matcher.group(); + if (url.indexOf(".png") != -1 || url.indexOf(".jpg") != -1 || url.indexOf(".jpeg") != -1 || url.indexOf(".gif") != -1) { + url = ""; + } else if (url.indexOf(".mp4") != -1 || url.indexOf(".webm") != -1 || url.indexOf(".ogg") != -1) { + url = ""; + } else if (url.indexOf(".wav") != -1 || url.indexOf(".mp3") != -1) { + url = ""; + } else { + url = "" + url + ""; + } + matcher.appendReplacement(sb, url); + } + matcher.appendTail(sb); + text = sb.toString(); + } else if (www) { + Matcher matcher = wwwRegex.matcher(text); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String url = matcher.group(); + matcher.appendReplacement(sb, "" + url + ""); + } + matcher.appendTail(sb); + text = sb.toString(); + } - /** - * displayTimestamp - * - * @param date Date - * @return String - * */ - public static String displayTimestamp(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar today = Calendar.getInstance(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { - writer.write("Today"); - } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { - writer.write("Yesterday"); - } else { - writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); - if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.YEAR))); - } - } - writer.write(", "); - writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - writer.write(":"); - if (calendar.get(Calendar.MINUTE) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - - return writer.toString(); - } + if (email) { + Matcher matcher = emailRegex.matcher(text); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String address = matcher.group(); + matcher.appendReplacement(sb, "" + address + ""); + } + matcher.appendTail(sb); + text = sb.toString(); + } + return text; + } - /** - * displayTime - * - * @param date Date - * @return String - * */ - public static String displayTime(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - writer.write(":"); - if (calendar.get(Calendar.MINUTE) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); - writer.write(":"); - if (calendar.get(Calendar.SECOND) < 10) { - writer.write("0"); - } - writer.write(String.valueOf(calendar.get(Calendar.SECOND))); - - return writer.toString(); - } - /** - * displayDate - * - * @param date Date - * @return String - * */ - public static String displayDate(Date date) { - if (date == null) { - return ""; - } - StringWriter writer = new StringWriter(); - Calendar today = Calendar.getInstance(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { - writer.write("Today"); - } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) - && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { - writer.write("Yesterday"); - } else { - writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); - if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { - writer.write(" "); - writer.write(String.valueOf(calendar.get(Calendar.YEAR))); - } - } - - return writer.toString(); - } - - /** - * Capitalize the first character of the string. - * - * @param text String - * @return String - */ - public static String capitalize(String text) { - if (text.length() == 0) { - return text; - } - return Character.toUpperCase(text.charAt(0)) + text.substring(1, text.length()); - } - - public static Random random() { - return random; - } - - public static int random(int max) { - return random().nextInt(max); - } - - public static T random(List list) { - if ((list == null) || list.isEmpty()) { - return null; - } - return list.get(random().nextInt(list.size())); - } + /** + * Replace reserved HTML character with their HTML escape codes. + * + * @param html String + * @return String + */ + public static String escapeHTML(String html) { + return html.replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("`", "`") + .replace("'", "'"); + } + + /** + * Strip the HTML tags from the text. + * + * @param html String + * @return String + */ + public static String stripTags(String html) { + if (html == null) { + return ""; + } + String result = html; + if ((html.indexOf('<') != -1) && (html.indexOf('>') != -1)) { + StringWriter writer = new StringWriter(); + TextStream stream = new TextStream(html); + while (!stream.atEnd()) { + String text = stream.upTo('<'); + writer.write(text); + int position = stream.getPosition(); + stream.skip(); + String word = stream.nextWord(); + if (word != null) { + if (word.equals("p")) { + writer.write("\n\n"); + } else if (word.equals("br")) { + writer.write("\n"); + } else if (word.equals("div")) { + writer.write("\n"); + } + stream.skipTo('>'); + if (stream.atEnd()) { + stream.setPosition(position); + writer.write(stream.upToEnd()); + } else { + stream.skip(); + } + } + } + result = writer.toString(); + } + if (result.contains("&")) { + result = result.replace(""", "\""); + result = result.replace("`", "`"); + result = result.replace("'", "'"); + result = result.replace("@", "@"); + result = result.replace("=", "="); + result = result.replace("<", "<"); + result = result.replace(">", ">"); + } + return result; + } + + /** + * displayTimestamp + * + * @param date Date + * @return String + */ + public static String displayTimestamp(Date date) { + if (date == null) { + return ""; + } + StringWriter writer = new StringWriter(); + Calendar today = Calendar.getInstance(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) + && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { + writer.write("Today"); + } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) + && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { + writer.write("Yesterday"); + } else { + writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); + writer.write(" "); + writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); + if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { + writer.write(" "); + writer.write(String.valueOf(calendar.get(Calendar.YEAR))); + } + } + writer.write(", "); + writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); + writer.write(":"); + if (calendar.get(Calendar.MINUTE) < 10) { + writer.write("0"); + } + writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); + + return writer.toString(); + } + + /** + * displayTime + * + * @param date Date + * @return String + */ + public static String displayTime(Date date) { + if (date == null) { + return ""; + } + StringWriter writer = new StringWriter(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); + writer.write(":"); + if (calendar.get(Calendar.MINUTE) < 10) { + writer.write("0"); + } + writer.write(String.valueOf(calendar.get(Calendar.MINUTE))); + writer.write(":"); + if (calendar.get(Calendar.SECOND) < 10) { + writer.write("0"); + } + writer.write(String.valueOf(calendar.get(Calendar.SECOND))); + + return writer.toString(); + } + + /** + * displayDate + * + * @param date Date + * @return String + */ + public static String displayDate(Date date) { + if (date == null) { + return ""; + } + StringWriter writer = new StringWriter(); + Calendar today = Calendar.getInstance(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) + && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { + writer.write("Today"); + } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) + && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { + writer.write("Yesterday"); + } else { + writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); + writer.write(" "); + writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); + if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { + writer.write(" "); + writer.write(String.valueOf(calendar.get(Calendar.YEAR))); + } + } + + return writer.toString(); + } + + /** + * Capitalize the first character of the string. + * + * @param text String + * @return String + */ + public static String capitalize(String text) { + if (text.length() == 0) { + return text; + } + return Character.toUpperCase(text.charAt(0)) + text.substring(1, text.length()); + } + + public static Random random() { + return random; + } + + public static int random(int max) { + return random().nextInt(max); + } + + public static T random(List list) { + if ((list == null) || list.isEmpty()) { + return null; + } + return list.get(random().nextInt(list.size())); + } } \ No newline at end of file -- Gitee From f16f5b8afb6dd909349f3ee2e5e2c60de9e698ad Mon Sep 17 00:00:00 2001 From: 258767-shengyu <1qaz2wsx> Date: Wed, 28 Jul 2021 12:42:16 +0800 Subject: [PATCH 2/4] checkstyle --- .../java/org/botlibre/sdk/MainAbility.java | 50 ++- .../org/botlibre/sdk/ability/ChatAbility.java | 96 +++++- .../org/botlibre/sdk/ability/HelpAbility.java | 12 +- .../botlibre/sdk/ability/LibreAbility.java | 23 ++ .../sdk/ability/actions/HttpAction.java | 87 ----- .../sdk/ability/actions/HttpChatAction.java | 70 ----- .../ability/actions/HttpConnectAction.java | 85 ----- .../sdk/ability/actions/HttpCreateAction.java | 78 ----- .../ability/actions/HttpCreateUserAction.java | 63 ---- .../sdk/ability/actions/HttpFetchAction.java | 111 ------- .../actions/HttpFetchActionOffline.java | 116 ------- .../actions/HttpFetchChatAvatarAction.java | 57 ---- .../ability/actions/HttpFetchWarAction.java | 37 --- .../ability/actions/HttpFlagIssueAction.java | 51 --- .../ability/actions/HttpFlagUserAction.java | 51 --- .../actions/HttpGetInstancesAction.java | 136 -------- .../ability/actions/HttpGetPostsAction.java | 71 ----- .../sdk/ability/actions/HttpResultAction.java | 75 ----- .../sdk/ability/actions/HttpUIAction.java | 72 ----- .../ability/actions/HttpUIResultAction.java | 73 ----- .../ability/dialog/LanguageDialogBuilder.java | 5 +- .../ability/dialog/SearchDialogBuilder.java | 1 + .../ability/dialog/SpinnerDialogBuilder.java | 5 +- .../sdk/ability/war/HttpChatWarAction.java | 37 --- .../sdk/ability/war/StartWarAbility.java | 12 +- .../java/org/botlibre/sdk/util/AsyncTask.java | 297 ------------------ .../java/org/botlibre/sdk/util/ResUtils.java | 8 +- .../org/botlibre/sdk/util/ToastUtils.java | 3 +- .../java/org/botlibre/sdk/MyApplication.java | 2 +- .../org/botlibre/sdk/ability/HelpAbility.java | 4 - .../botlibre/sdk/ability/LibreAbility.java | 6 +- .../sdk/ability/ListTemplateView.java | 33 +- .../sdk/ability/actions/HttpAction.java | 84 ----- .../ability/actions/HttpCreateUserAction.java | 63 ---- .../sdk/ability/actions/HttpFetchAction.java | 119 ------- .../ability/actions/HttpFlagUserAction.java | 51 --- .../actions/HttpGetAvatarMediaAction.java | 60 ---- .../actions/HttpGetInstancesAction.java | 57 ---- .../actions/HttpGetLearningAction.java | 62 ---- .../actions/HttpGetTemplatesAction.java | 41 --- .../sdk/ability/actions/HttpResultAction.java | 75 ----- .../sdk/ability/actions/HttpUIAction.java | 72 ----- .../ability/actions/HttpUIResultAction.java | 73 ----- .../sdk/ability/war/HttpChatWarAction.java | 37 --- .../sdk/ability/war/StartWarAbility.java | 18 +- .../sdk/util/ApplicationJumpUtil.java | 1 - .../java/org/botlibre/sdk/util/AsyncTask.java | 297 ------------------ .../org/botlibre/sdk/util/ToastUtils.java | 3 +- .../org/botlibre/sdk/MainAbilityTest.java | 48 --- .../sdk/ability/CreateUserAbility.java | 12 +- .../botlibre/sdk/ability/LibreAbility.java | 12 +- .../botlibre/sdk/ability/LoginAbility.java | 24 +- .../sdk/ability/actions/HttpAction.java | 66 ---- .../ability/actions/HttpConnectAction.java | 74 ----- .../ability/actions/HttpCreateUserAction.java | 59 ---- .../sdk/ability/actions/HttpUIAction.java | 88 ------ .../org/botlibre/sdk/config/AvatarConfig.java | 180 ----------- .../org/botlibre/sdk/config/ChatResponse.java | 5 +- .../botlibre/sdk/config/ResponseConfig.java | 10 +- .../sdk/config/ScriptSourceConfig.java | 19 -- .../java/org/botlibre/sdk/util/AsyncTask.java | 297 ------------------ .../org/botlibre/sdk/ability/ChatAbility.java | 74 ++++- .../org/botlibre/sdk/ability/HelpAbility.java | 1 - .../botlibre/sdk/ability/LibreAbility.java | 23 ++ .../botlibre/sdk/ability/LoginAbility.java | 5 +- .../sdk/ability/actions/HttpAction.java | 94 ------ .../sdk/ability/actions/HttpChatAction.java | 163 ---------- .../ability/actions/HttpConnectAction.java | 85 ----- .../ability/actions/HttpCreateUserAction.java | 59 ---- .../actions/HttpFetchChatAvatarAction.java | 57 ---- .../actions/HttpGetInstancesAction.java | 76 ----- .../actions/HttpGetTemplatesAction.java | 55 ---- .../sdk/ability/actions/HttpResultAction.java | 75 ----- .../sdk/ability/actions/HttpUIAction.java | 72 ----- .../ability/actions/HttpUIResultAction.java | 73 ----- .../sdk/ability/war/HttpChatWarAction.java | 37 --- .../sdk/ability/war/StartWarAbility.java | 28 +- .../java/org/botlibre/sdk/util/AsyncTask.java | 6 +- .../org/botlibre/sdk/util/ToastUtils.java | 3 +- .../org/botlibre/sdk/MainAbilityTest.java | 39 --- 80 files changed, 365 insertions(+), 4494 deletions(-) delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchActionOffline.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java delete mode 100644 BotLibre/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java delete mode 100644 BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java delete mode 100644 BotLibreOffline/entry/src/ohosTest/java/org/botlibre/sdk/MainAbilityTest.java delete mode 100644 PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java delete mode 100644 PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java delete mode 100644 PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java delete mode 100644 PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java delete mode 100644 PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java delete mode 100644 SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java delete mode 100644 SantaBot/entry/src/ohosTest/java/org/botlibre/sdk/MainAbilityTest.java diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java index da3cb81..ed62b43 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java @@ -30,8 +30,6 @@ import org.botlibre.sdk.ability.HelpAbility; import org.botlibre.sdk.ability.LibreAbility; import org.botlibre.sdk.ability.ListTemplateView; import org.botlibre.sdk.ability.LoginAbility; -import org.botlibre.sdk.ability.actions.HttpAction; -import org.botlibre.sdk.ability.actions.HttpFetchActionOffline; import org.botlibre.sdk.ability.adapter.SpinnerAdapter; import org.botlibre.sdk.ability.avatar.AvatarSelection; import org.botlibre.sdk.ability.dialog.LanguageDialogBuilder; @@ -54,6 +52,7 @@ import org.botlibre.sdk.config.UserConfig; import org.botlibre.sdk.config.VoiceConfig; import org.botlibre.sdk.config.WebMediumConfig; import org.botlibre.sdk.micro.MicroConnection; +import org.botlibre.sdk.util.LogUtils; import org.botlibre.sdk.util.PreferencesUtils; import java.awt.*; @@ -144,6 +143,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag * have this launch the bot, forum, or channel. */ private static LaunchType launchType = LaunchType.Browse; + private MicroConnection microConnection; @Override public void selectItem(String select) { @@ -1776,14 +1776,52 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag config.name = MainAbility.launchInstanceName; AvatarSelection.saveSelectedAvatar(templates.getTitle()); setOfflineSelectedImage(templates.getImageId()); - HttpAction action = new HttpFetchActionOffline(this, config, true); - action.execute(); + WebMediumConfig finalConfig = config; + WebMediumConfig finalConfig1 = config; + WebMediumConfig finalConfig2 = config; + runWork(new Runnable() { + @Override + public void run() { + try { + MainAbility.setOnline(false); + microConnection = (MicroConnection) MainAbility.getConnection(); + microConnection.fetch(finalConfig); + } catch (Exception exception) { + LogUtils.error("HttpFetchAction", exception.toString()); + } + try { + MainAbility.setInstance(finalConfig1); + Class childAbility = MainAbility.getAbility(finalConfig2); + startOpenAbility(MainAbility.this, childAbility.getName()); + } catch (Exception error) { + MainAbility.error(error.getMessage(), error, MainAbility.this); + } + } + }); } else { config = new InstanceConfig(); config.name = MainAbility.launchInstanceName; config.id = MainAbility.launchInstanceId; - HttpAction action = new HttpFetchActionOffline(this, config, true); - action.execute(); + WebMediumConfig finalConfig3 = config; + runWork(new Runnable() { + @Override + public void run() { + try { + MainAbility.setOnline(false); + microConnection = (MicroConnection) MainAbility.getConnection(); + microConnection.fetch(finalConfig3); + } catch (Exception exception) { + LogUtils.error("HttpFetchAction", exception.toString()); + } + try { + MainAbility.setInstance(finalConfig3); + Class childAbility = MainAbility.getAbility(finalConfig3); + startOpenAbility(MainAbility.this, childAbility.getName()); + } catch (Exception error) { + MainAbility.error(error.getMessage(), error, MainAbility.this); + } + } + }); } } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java index e774eb9..fe354c7 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java @@ -39,9 +39,6 @@ import ohos.multimodalinput.event.TouchEvent; import ohos.utils.PacMap; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpAction; -import org.botlibre.sdk.ability.actions.HttpChatAction; -import org.botlibre.sdk.ability.actions.HttpFetchChatAvatarAction; import org.botlibre.sdk.config.AvatarConfig; import org.botlibre.sdk.config.ChatConfig; import org.botlibre.sdk.config.ChatResponse; @@ -65,7 +62,7 @@ import java.util.UUID; * Ability for chatting with a bot. * To launch this Ability from your app you can use the HttpFetchAction passing the bot id or name as a config, and launch=true. * - * @since 2021-05-10 + * @since 2021-05-10 */ @SuppressWarnings("deprecation") public class ChatAbility extends LibreAbility { @@ -159,8 +156,6 @@ public class ChatAbility extends LibreAbility { private boolean threadIsOn = false; - - /** * 文本转语音 语音播报 */ @@ -419,6 +414,7 @@ public class ChatAbility extends LibreAbility { } }; + private Exception exception; @Override @@ -660,8 +656,27 @@ public class ChatAbility extends LibreAbility { } catch (Exception exception) { } } - HttpAction action = new HttpChatAction(ChatAbility.this, config); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().chat(config); + runUI(new Runnable() { + @Override + public void run() { + if (exception != null) { + MainAbility.errorInfo(1, exception.getMessage(), exception, ChatAbility.this); + return; + } + try { + } catch (Exception error) { + exception = error; + MainAbility.error(exception.getMessage(), exception, ChatAbility.this); + return; + } + } + }); + } + }); } }; thread1.start(); @@ -812,8 +827,27 @@ public class ChatAbility extends LibreAbility { handler.sendEvent(LIST_CONTAINER); - HttpChatAction action = new HttpChatAction(ChatAbility.this, config); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().chat(config); + runUI(new Runnable() { + @Override + public void run() { + if (exception != null) { + MainAbility.errorInfo(1, exception.getMessage(), exception, ChatAbility.this); + return; + } + try { + } catch (Exception error) { + exception = error; + MainAbility.error(exception.getMessage(), exception, ChatAbility.this); + return; + } + } + }); + } + }); editText.setText(""); resetToolbar(); @@ -883,8 +917,22 @@ public class ChatAbility extends LibreAbility { this.videoLayout.setVisibility(Component.HIDE); } AvatarConfig avatarConfig = (AvatarConfig) this.avatar.credentials(); - HttpFetchChatAvatarAction action = new HttpFetchChatAvatarAction(this, avatarConfig); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().fetch(avatarConfig); + runUI(new Runnable() { + @Override + public void run() { + try { + } catch (Exception error) { + MainAbility.error(error.getMessage(), error, ChatAbility.this); + return; + } + } + }); + } + }); } MainAbility.setBrowsing(false); if (this.changingVoice) { @@ -931,8 +979,27 @@ public class ChatAbility extends LibreAbility { config.conversation = MainAbility.getConversation(); config.disconnect = true; - HttpChatAction action = new HttpChatAction(this, config); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().chat(config); + runUI(new Runnable() { + @Override + public void run() { + if (exception != null) { + MainAbility.errorInfo(1, exception.getMessage(), exception, ChatAbility.this); + return; + } + try { + } catch (Exception error) { + exception = error; + MainAbility.error(exception.getMessage(), exception, ChatAbility.this); + return; + } + } + }); + } + }); } muteMicBeep(false); if (ttsClient != null) { @@ -1156,6 +1223,7 @@ public class ChatAbility extends LibreAbility { handler.sendEvent(BEGIN_LISTENING); } + private void setMicIcon(boolean on, boolean recording) { try { if (!on) { diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java index e259b8a..a973ac6 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java @@ -18,20 +18,18 @@ package org.botlibre.sdk.ability; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.utils.net.Uri; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpFetchAction; -import org.botlibre.sdk.ability.actions.HttpResultAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.ChannelConfig; import org.botlibre.sdk.config.ForumConfig; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; -import ohos.agp.components.Button; -import ohos.agp.components.Component; -import ohos.utils.net.Uri; /** * Help page. diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index f4b8bd4..420fc63 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -21,6 +21,8 @@ package org.botlibre.sdk.ability; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; /** * Generic Ability for common behavior. @@ -85,4 +87,25 @@ public abstract class LibreAbility extends Ability { intent.setOperation(operation); return intent; } + + /** + * runUI + * + * @param runnable run + */ + public static void runUI(Runnable runnable) { + EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner()); + eventHandler.postSyncTask(runnable); + } + + /** + * 子线程执行任务 + * + * @param runnable run + */ + public static void runWork(Runnable runnable) { + EventRunner runner = EventRunner.create(true); + EventHandler eventHandler = new EventHandler(runner); + eventHandler.postTask(runnable, 0, EventHandler.Priority.IMMEDIATE); + } } diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java deleted file mode 100644 index 684bfb0..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java +++ /dev/null @@ -1,87 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.util.AsyncTask; -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; - -public abstract class HttpAction extends AsyncTask { - protected Ability ability; - protected Exception exception; - - public HttpAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } - - /** - * 启动ability - * - * @param ability ability - * @param name name - */ - public void startOpenAbility(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbility(intent); - } - - public Intent getIntent(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - return intent; - } - - /** - * 启动ability - * - * @param ability ability - * @param name name - * @param requestCode requestCode - */ - public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbilityForResult(intent, requestCode); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java deleted file mode 100644 index edc0ece..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; -import ohos.aafwk.ability.Ability; - - -public class HttpChatAction extends HttpAction { - ChatConfig config; - - public HttpChatAction(Ability ability, ChatConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().chat(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPreExecute() { - if (!this.config.disconnect) { - super.onPreExecute(); - } - } - - @Override - protected void onPostExecute(String xml) { - if (this.config.disconnect) { - return; - } - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); - return; - } - try { - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java deleted file mode 100644 index cdc427f..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java +++ /dev/null @@ -1,85 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; - -public class HttpConnectAction extends HttpUIResultAction { - UserConfig config; - boolean finish; - - public HttpConnectAction(Ability ability, UserConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - doInBackground(); - } - - // @Override - public void doInBackground() { - loadingDialog(); - try { - this.config = MainAbility.getConnection().connect(config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - } - onPostExecute(); - } - - // @Override - protected void onPostExecute() { -// super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.setUser(this.config); - if (this.ability instanceof MainAbility) { - ((MainAbility) this.ability).resetView(); - } - - if (this.finish) { - - Preferences cookies = PreferencesUtils.getPreferences(ability); - cookies.putString("user", MainAbility.getUser().user); - cookies.putString("token", MainAbility.getUser().token); - cookies.flushSync(); - - this.ability.terminateAbility(); - } - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - - Preferences cookies = PreferencesUtils.getPreferences(this.ability); - cookies.putString("user", null); - cookies.putString("token", null); - cookies.flushSync(); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java deleted file mode 100644 index f0212cf..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateAction.java +++ /dev/null @@ -1,78 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; - -public class HttpCreateAction extends HttpUIAction { - - WebMediumConfig config; - boolean finish; - - public HttpCreateAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - this.finish = true; - } - - public HttpCreateAction(Ability ability, WebMediumConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.getConnection().create(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @SuppressWarnings("rawtypes") - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.setInstance(this.config); - - if (this.finish) { - this.ability.terminateAbility(); - } - - Preferences cookies = PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), this.config.name); - cookies.flushSync(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java deleted file mode 100644 index 0211740..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; -import ohos.app.Context; - -public class HttpCreateUserAction extends HttpUIResultAction { - UserConfig config; - - public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { - super(ability); - this.config = config; - doInBackground(); - } - - protected void doInBackground() { - try { - this.config = MainAbility.getConnection().create(ability, this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - - if (this.exception != null) { - return; - } - try { - MainAbility.setUser(this.config); - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - removeDialog(); - return; - } - - } - - // @Override - public void onPostExecute(String xml) { -// super.onPostExecute(xml); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java deleted file mode 100644 index 3a6ca33..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java +++ /dev/null @@ -1,111 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ChannelConfig; -import org.botlibre.sdk.config.DomainConfig; -import org.botlibre.sdk.config.ForumConfig; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.util.PreferencesUtils; - -import static org.botlibre.sdk.MainAbility.*; - -public class HttpFetchAction extends HttpUIResultAction { - WebMediumConfig config; - boolean launch; - - public HttpFetchAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - public HttpFetchAction(Ability ability, WebMediumConfig config, boolean launch) { - super(ability); - this.config = config; - this.launch = launch; - doInBackground(); - } - - public void doInBackground() { - loadingDialog(); - try { - this.config = getConnection().fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - onPostExecute(); - } - - @SuppressWarnings("rawtypes") -// @Override - public void onPostExecute() { - if (this.exception != null) { - return; - } - try { - setInstance(this.config); - - Preferences cookies = PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), this.config.name); - cookies.flushSync(); - - Class childAbility = getAbility(this.config); - if (this.launch && !this.config.isExternal) { - if (this.config instanceof ChannelConfig) { - } else if (this.config instanceof InstanceConfig) { - } else if (this.config instanceof DomainConfig) { - getConnection().setDomain((DomainConfig) this.config); - setDomain((DomainConfig) this.config); - setForumCategories(null); - setChannelTags(null); - setChannelCategories(null); - setDomainTags(null); - setDomainCategories(null); - setGraphicTags(null); - setGraphicCategories(null); - - setType(getDefaultType()); - startOpenAbility(this.ability, MainAbility.class.getName()); - return; - } else if (this.config instanceof ForumConfig) { - BrowseConfig config = new BrowseConfig(); - - config.typeFilter = "Public"; - config.type = "Post"; - config.instance = getInstance().id; - config.sort = "date"; - return; - } - } - startOpenAbility(this.ability, childAbility.getName()); - } catch (Exception error) { - this.exception = error; - error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchActionOffline.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchActionOffline.java deleted file mode 100644 index 95ab96c..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchActionOffline.java +++ /dev/null @@ -1,116 +0,0 @@ -/****************************************************************************** - * - * Copyright 2017 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.components.Text; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.ChatAbility; -import org.botlibre.sdk.ability.ListTemplateView; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.micro.MicroConnection; -import org.botlibre.sdk.util.LogUtils; - -import java.util.Optional; - -public class HttpFetchActionOffline extends HttpUIAction { - WebMediumConfig config; - MicroConnection microConnection = new MicroConnection(); - boolean launch; - - public HttpFetchActionOffline(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - - public HttpFetchActionOffline(Ability ability, WebMediumConfig config, boolean launch) { - super(ability); - this.config = config; - this.launch = launch; - } - - @Override - protected void onPreExecute() { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - Text title = (Text) layout.findComponentById(ResourceTable.Id_title); - title.setText("Initializing Bot"); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100, 150); - this.dialog.show(); - } - - @Override - protected String doInBackground(Void... params) { - - try { - //switch connections. - MainAbility.setOnline(false); - microConnection = (MicroConnection) MainAbility.getConnection(); - this.config = microConnection.fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - LogUtils.error("HttpFetchAction", exception.toString()); - return ""; - } - - if (this.ability instanceof ListTemplateView) { - this.ability.terminateAbility(); - } - if (this.exception != null) { - return ""; - } - try { - MainAbility.setInstance(this.config); - Class childAbility = MainAbility.getAbility(this.config); - if (this.launch && !this.config.isExternal) { - if (this.config instanceof InstanceConfig) { - childAbility = ChatAbility.class; - } - } - startOpenAbility(this.ability, childAbility.getName()); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return ""; - } - return ""; - } - - @SuppressWarnings("rawtypes") - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java deleted file mode 100644 index ab2e355..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFetchChatAvatarAction extends HttpUIAction { - AvatarConfig config; - - public HttpFetchChatAvatarAction(Ability ability, AvatarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.getConnection().fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java deleted file mode 100644 index d76319b..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFetchWarAction extends HttpFetchAction { - - public HttpFetchWarAction(Ability ability, WebMediumConfig config) { - super(ability, config); - } - - // @Override - public void onPostExecute(String xml) { -// super.superOnPostExecute(xml); -// StartWarAbility.bot1 = (InstanceConfig)this.config; -// ((StartWarAbility)this.ability).resetView(); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java deleted file mode 100644 index d24138a..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagIssueAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.IssueConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFlagIssueAction extends HttpUIAction { - IssueConfig config; - - public HttpFlagIssueAction(Ability ability, IssueConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.getIssue().isFlagged = true; - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java deleted file mode 100644 index 9f857eb..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFlagUserAction extends HttpUIAction { - UserConfig config; - - public HttpFlagUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java deleted file mode 100644 index 2739885..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java +++ /dev/null @@ -1,136 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpGetInstancesAction extends HttpUIResultAction { - - BrowseConfig config; - List instances; - boolean finish = false; - - public HttpGetInstancesAction(Ability ability, BrowseConfig config) { - super(ability); - this.config = config; - doInBackground(); - } - - public HttpGetInstancesAction(Ability ability, BrowseConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - doInBackground(); - } - - public HttpGetInstancesAction(Ability ability, BrowseConfig config, boolean finish, boolean CustomAvatar) { - super(ability); - this.config = config; - this.finish = finish; - } - - public void doInBackground() { - loadingDialog(); - try { - this.instances = MainAbility.getConnection().browse(ability, config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - onPostExecute(); - } - -// @Override -// protected String doInBackground(Void... params) { -// -// return ""; -// } - - // @Override - public void onPostExecute() { -// super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setInstances(this.instances); - - if (this.finish) { - this.ability.terminateAbility(); - } -// Intent intent = null; -// MainAbility.browse = this.config; -// if (config.type.equals("Forum")) { -// intent = getIntent(this.ability, BrowseForumAbility.class.getName()); -// } else if (config.type.equals("Channel")) { -// intent = getIntent(this.ability, BrowseChannelAbility.class.getName()); -// } else if (config.type.equals("Domain")) { -// intent = getIntent(this.ability, BrowseDomainAbility.class.getName()); -// } else if (config.type.equals("Avatar")) { -// intent = getIntent(this.ability, BrowseAvatarAbility.class.getName()); -// } else if (config.type.equals("Graphic")) { -// intent = getIntent(this.ability, BrowseGraphicAbility.class.getName()); -// if (this.CustomAvatar) { -// //only happens when CustomAvatar is called -// intent.setParam("dataName", "Custom Avatar"); -// intent.setParam("dataCustomAvatar", true); -// } else { -// intent.setParam("dataCustomAvatar", false); -// } -// -// } else if (config.type.equals("Script")) { -// if (MainAbility.importingBotScript) { -// List onlyScripts = new ArrayList(); -// -// for (int i = 0; i < MainAbility.instances.size(); i++) { -// ScriptConfig config = (ScriptConfig) MainAbility.instances.get(i); -// if (config.categories.contains("Self") || config.categories.contains("AIML")) { -// onlyScripts.add(config); -// } -// } -// MainAbility.instances = onlyScripts; -// } else if (MainAbility.importingBotLog) { -// List onlyScripts = new ArrayList(); -// -// for (int i = 0; i < MainAbility.instances.size(); i++) { -// ScriptConfig config = (ScriptConfig) MainAbility.instances.get(i); -// if (config.categories.contains("Log") || config.categories.contains("AIML") || config.categories.contains("Response")) { -// onlyScripts.add(config); -// } -// } -// MainAbility.instances = onlyScripts; -// } -// intent = getIntent(this.ability, BrowseScriptAbility.class.getName()); -// } else { -// intent = getIntent(this.ability, BrowseAbility.class.getName()); -// } -// -// //for result only happens when RequestAbility calls it. -// if (this.CustomAvatar) { -// this.ability.startAbilityForResult(intent, 1); -// } else { -// this.ability.startAbility(intent); -// } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java deleted file mode 100644 index eea8b9f..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetPostsAction.java +++ /dev/null @@ -1,71 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import java.util.List; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ForumPostConfig; -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; - -public class HttpGetPostsAction extends HttpUIAction { - BrowseConfig config; - List posts; - boolean finish = false; - - public HttpGetPostsAction(Ability Ability, BrowseConfig config) { - super(Ability); - this.config = config; - } - - public HttpGetPostsAction(Ability Ability, BrowseConfig config, boolean finish) { - super(Ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.posts = MainAbility.getConnection().getPosts(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setPosts(this.posts); - - if (this.finish) { - this.ability.terminateAbility(); - } - MainAbility.setBrowsePosts(this.config); - Intent intent = new Intent(); - this.ability.startAbility(intent); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java deleted file mode 100644 index 88568b1..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java +++ /dev/null @@ -1,75 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; - -public abstract class HttpResultAction { - protected Ability ability; - protected Exception exception; - - public HttpResultAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } - - /** - * 启动ability - * - * @param ability ability - * @param name name - */ - public void startOpenAbility(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbility(intent); - } - - /** - * 启动ability - * - * @param ability ability - * @param name name - * @param requestCode requestCode - */ - public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbilityForResult(intent, requestCode); - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java deleted file mode 100644 index 43ef52f..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java +++ /dev/null @@ -1,72 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.util.LogUtils; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; - -import java.util.Optional; - -public abstract class HttpUIAction extends HttpAction { - protected CommonDialog dialog; - - public HttpUIAction(Ability Ability) { - super(Ability); - } - - // 加载 - public void loadingDialog() { - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100, 150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } - - public void removeDialog() { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java deleted file mode 100644 index b79ac22..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.ResUtils; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; - -import java.util.Optional; - -public abstract class HttpUIResultAction extends HttpResultAction { - protected CommonDialog dialog; - - public HttpUIResultAction(Ability Ability) { - super(Ability); - } - - // 加载 - public void loadingDialog() { - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100, 150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } - - public void removeDialog() { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1, ResUtils.getString(ability, ResourceTable.String_exception), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java index aa65364..dcd20ae 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java @@ -33,6 +33,7 @@ import org.botlibre.sdk.util.Constant; import java.util.Optional; + /** * 语言对话框 * @@ -66,8 +67,8 @@ public class LanguageDialogBuilder { .parse(ResourceTable.Layout_spinner_dialog, null, false); mCommonDialog.setContentCustomComponent(layout) - .setAlignment(LayoutAlignment.CENTER). - setSize(displayAttributes.width - Constant.FIVEZORE, displayAttributes.width) + .setAlignment(LayoutAlignment.CENTER) + .setSize(displayAttributes.width - Constant.FIVEZORE, displayAttributes.width) .setAutoClosable(true) .setTransparent(false) .show(); diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java index a41f960..c126483 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SearchDialogBuilder.java @@ -32,6 +32,7 @@ import org.botlibre.sdk.util.Constant; import java.util.Optional; + /** * 搜索对话框 * diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java index 90e2d5d..3cef01c 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/SpinnerDialogBuilder.java @@ -33,6 +33,7 @@ import org.botlibre.sdk.util.Constant; import java.util.Optional; + /** * 对话框 * @@ -67,12 +68,12 @@ public class SpinnerDialogBuilder { null, false); mCommonDialog.setContentCustomComponent(layout) .setAlignment(LayoutAlignment.CENTER) - .setSize(displayAttributes.width - Constant.FIVEZORE,displayAttributes.width) + .setSize(displayAttributes.width - Constant.FIVEZORE, displayAttributes.width) .setAutoClosable(true) .setTransparent(false) .show(); - listContainer = (ListContainer)layout.findComponentById(ResourceTable.Id_typeSpin); + listContainer = (ListContainer) layout.findComponentById(ResourceTable.Id_typeSpin); SpinnerAdapter spinner = new SpinnerAdapter(context, MainAbility.getTypes()); listContainer.setItemProvider(spinner); diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java deleted file mode 100644 index 2f0b255..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.botlibre.sdk.ability.war; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ability.actions.HttpUIAction; -import org.botlibre.sdk.config.InstanceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpChatWarAction extends HttpUIAction { - ChatWarConfig config; - InstanceConfig instance; - - public HttpChatWarAction(Ability ability, ChatWarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - InstanceConfig instance = new InstanceConfig(); - this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setInstance(this.instance); - } - -} \ No newline at end of file diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java index 53f3fbf..7369b71 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java @@ -19,20 +19,18 @@ package org.botlibre.sdk.ability.war; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.TextField; +import ohos.data.preferences.Preferences; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; import org.botlibre.sdk.ability.LibreAbility; -import org.botlibre.sdk.ability.actions.HttpFetchWarAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.WebMediumConfig; import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.content.Intent; -import ohos.agp.components.Button; -import ohos.agp.components.Component; -import ohos.agp.components.Text; -import ohos.agp.components.TextField; -import ohos.data.preferences.Preferences; import java.util.ArrayList; import java.util.List; diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java deleted file mode 100644 index 3b8c833..0000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.util; - -import ohos.eventhandler.EventHandler; -import ohos.eventhandler.EventRunner; -import ohos.eventhandler.InnerEvent; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; -import java.util.concurrent.FutureTask; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * MyAsyncTask - * - * @param - * @param - * @param - * @since 2021-05-08 - */ -public abstract class AsyncTask { - private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); - private static final int CORE_COUNT = CPU_COUNT + 1; - private static final int MAX_COUNT = CPU_COUNT * 2 + 1; - private static final int POST_EXECUTE = 0x00001; - private static final int PUBLISH_PROGRSS = 0x00002; - private static final int KEEP_ALIVE = 1; - private static final BlockingQueue POOLWORKQUEUE = - new LinkedBlockingQueue(128); - private static final ThreadFactory STHREADFACTORY = new ThreadFactory() { - private final AtomicInteger mCount = new AtomicInteger(1); - - /** - * newThread - * - * @param r runnable - * @return re - */ - public Thread newThread(Runnable r) { - return new Thread(r, "AsyncTask #" + mCount.getAndIncrement()); - } - }; - private static final Executor MEXECUTOR = new ThreadPoolExecutor(CORE_COUNT, MAX_COUNT, KEEP_ALIVE, - TimeUnit.SECONDS, POOLWORKQUEUE, STHREADFACTORY); - - private static InnerUiHandler mUIHandler; - private final WorkRunnable mWork; - private final FutureTask mFutureTask; - private volatile Status mStatus = Status.PENDING; - - /** - * 构造函数 - */ - public AsyncTask() { - /** - * 构造函数中初始化 - */ - mWork = new WorkRunnable() { - /** - * call - * - * @return re - * @throws Exception - */ - @Override - public Result call() throws Exception { - Result result = doInBackground(paramses); - return result; - } - }; - /** - * 构造函数中初始化 - */ - mFutureTask = new FutureTask(mWork) { - @Override - protected void done() { - super.done(); - try { - postResult(super.get()); - } catch (InterruptedException | ExecutionException e) { - e.getMessage(); - } - } - }; - } - - private static EventHandler getHandler() { - synchronized (AsyncTask.class) { - if (mUIHandler == null) { - mUIHandler = new InnerUiHandler(); - } - return mUIHandler; - } - } - - - /** - * 用来获取futuretask执行完成的结果 - * - * @return result - * @throws InterruptedException - * @throws ExecutionException - */ - public final Result get() throws InterruptedException, ExecutionException { - return mFutureTask.get(); - } - - private void postResult(Result result) { - getHandler().sendEvent(InnerEvent.get(POST_EXECUTE)); - } - - /** - * 可以回调的一些函数 - */ - protected void onPreExecute() { - } - - /** - * doInBackground - * - * @param params params - * @return result - */ - protected abstract Result doInBackground(Params[] params); - - /** - * onPostExecute - * - * @param result result - */ - protected void onPostExecute(Result result) { - } - - /** - * onCancelled - */ - protected void onCancelled() { - } - - /** - * onProgressUpdate - * - * @param progress progress - */ - protected void onProgressUpdate(Progress[] progress) { - } - - /** - * InnerUiHandler - * - * @since 2021-04-25 - */ - private static class InnerUiHandler extends EventHandler { - InnerUiHandler() { - super(EventRunner.getMainEventRunner()); - } - - @Override - protected void processEvent(InnerEvent event) { - super.processEvent(event); - switch (event.eventId) { - case POST_EXECUTE: - AsyncTaskResult result = (AsyncTaskResult) event.object; - result.myAsyncTask.postResult(result.mData); - break; - case PUBLISH_PROGRSS: - AsyncTaskResult result2 = (AsyncTaskResult) event.object; - result2.myAsyncTask.onProgressUpdate(result2.mData); - break; - default: - break; - } - } - } - - /** - * publishProgress - * - * @param progress progress - */ - public final void publishProgress(Progress... progress) { - getHandler().sendEvent(InnerEvent.get(PUBLISH_PROGRSS, - new AsyncTaskResult(this, progress))); - } - - /** - * InnerUiHandler - * - * @since 2021-04-25 - */ - public enum Status { - /** - * Indicates that the task has not been executed yet. - */ - PENDING, - /** - * Indicates that the task is running. - */ - RUNNING, - /** - * Indicates that {@link AsyncTask#onPostExecute} has finished. - */ - FINISHED, - } - - /** - * execute - * - * @param params params - * @return async - */ - public final AsyncTask execute(Params... params) { - return executeOnExecutor(MEXECUTOR, params); - } - - /** - * executeOnExecutor - * - * @param executor executor - * @param paramses paramses - * @return async - * @throws IllegalStateException - */ - public final AsyncTask executeOnExecutor(Executor executor, Params[] paramses) { - if (mStatus != Status.PENDING) { - switch (mStatus) { - case RUNNING: - - throw new IllegalStateException("Cannot execute task:" - + " the task is already running."); - case FINISHED: - throw new IllegalStateException("Cannot execute task:" - + " the task has already been executed " - + "(a task can be executed only once)"); - default: - break; - } - } - - mStatus = Status.RUNNING; - onPreExecute(); - mWork.paramses = paramses; - executor.execute(mFutureTask); - return this; - } - - /** - * InnerUiHandler - * - * @param paramses - * @param result - * @since 2021-04-25 - */ - private abstract static class WorkRunnable implements Callable { - /** - * execute - */ - Params[] paramses; - } - - /** - * InnerUiHandler - * - * @param data - * @since 2021-04-25 - */ - private static class AsyncTaskResult { - AsyncTask myAsyncTask; - Data[] mData; - - AsyncTaskResult(AsyncTask myAsyncTask, Data[] data) { - this.myAsyncTask = myAsyncTask; - this.mData = data; - } - } - -} diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ResUtils.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ResUtils.java index 81de12c..d3b7d69 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ResUtils.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ResUtils.java @@ -93,8 +93,8 @@ public final class ResUtils { /** * 设置button背景 * - * @param button - * @param resId + * @param button 控件 + * @param resId 资源id */ public static void setBackground(Button button, int resId) { Resource bgResource = null; @@ -111,8 +111,8 @@ public final class ResUtils { /** * 设置button背景 * - * @param ability - * @param checkbox + * @param ability 上下文 + * @param checkbox 控件 */ public static void setCheckboxBg(Ability ability, Checkbox checkbox) { StateElement stateElement = new StateElement(); diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java index 0117f4c..dc514a4 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java @@ -15,6 +15,7 @@ package org.botlibre.sdk.util; +import org.botlibre.sdk.ResourceTable; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; import ohos.agp.components.LayoutScatter; @@ -22,7 +23,7 @@ import ohos.agp.components.Text; import ohos.agp.utils.LayoutAlignment; import ohos.agp.window.dialog.ToastDialog; import ohos.app.Context; -import org.botlibre.sdk.ResourceTable; + /** * ToastUtils diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MyApplication.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MyApplication.java index ed61515..7ddc6af 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MyApplication.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MyApplication.java @@ -32,7 +32,7 @@ public class MyApplication extends AbilityPackage { /** * setmContext * - * @param mContext + * @param mContext 上下文 */ public static void setmContext(Context mContext) { MyApplication.mContext = mContext; diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java index b52e03f..dbfd867 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java @@ -20,9 +20,6 @@ package org.botlibre.sdk.ability; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpFetchAction; -import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; -import org.botlibre.sdk.ability.actions.HttpResultAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.ChannelConfig; import org.botlibre.sdk.config.ForumConfig; @@ -43,7 +40,6 @@ public class HelpAbility extends LibreAbility implements Component.ClickedListen @Override public void onStart(Intent intent) { super.onStart(intent); -// setContentView(R.layout.ability_help); super.setUIContent(ResourceTable.Layout_ability_help); MainAbility.setOnline(true); this.instance = MainAbility.getInstance(); diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index 772f19f..3a14f50 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -67,7 +67,7 @@ public abstract class LibreAbility extends Ability { /** * runUI * - * @param runnable + * @param runnable run */ public static void runUI(Runnable runnable) { EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner()); @@ -78,13 +78,11 @@ public abstract class LibreAbility extends Ability { /** * 子线程执行任务 * - * @param runnable + * @param runnable run */ public static void runWork(Runnable runnable) { - //开启线程 EventRunner runner = EventRunner.create(true); EventHandler eventHandler = new EventHandler(runner); eventHandler.postTask(runnable, 0, EventHandler.Priority.IMMEDIATE); - } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java index 5665b77..40d7369 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java @@ -17,21 +17,8 @@ ******************************************************************************/ package org.botlibre.sdk.ability; -import java.util.ArrayList; -import java.util.List; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpAction; -import org.botlibre.sdk.ability.actions.HttpGetTemplatesAction; -import org.botlibre.sdk.ability.avatar.AvatarSelection; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.micro.MicroConnection; -import org.botlibre.sdk.util.PreferencesUtils; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; -import org.botlibre.sdk.config.OfflineTemplateConfig; import ohos.agp.components.BaseItemProvider; import ohos.agp.components.Component; import ohos.agp.components.ComponentContainer; @@ -40,6 +27,17 @@ import ohos.agp.components.LayoutScatter; import ohos.agp.components.ListContainer; import ohos.agp.components.Text; import ohos.data.preferences.Preferences; +import org.botlibre.sdk.MainAbility; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.ability.avatar.AvatarSelection; +import org.botlibre.sdk.config.InstanceConfig; +import org.botlibre.sdk.config.OfflineTemplateConfig; +import org.botlibre.sdk.config.WebMediumConfig; +import org.botlibre.sdk.micro.MicroConnection; +import org.botlibre.sdk.util.PreferencesUtils; + +import java.util.ArrayList; +import java.util.List; public class ListTemplateView extends LibreAbility { private static boolean offlineTemplate = false; @@ -102,9 +100,9 @@ public class ListTemplateView extends LibreAbility { runUI(new Runnable() { @Override public void run() { - if(MainAbility.getLaunchInstanceName().contains("Assistance")){ + if (MainAbility.getLaunchInstanceName().contains("Assistance")) { startOpenAbility(ListTemplateView.this, ChatAbility2.class.getName()); - }else{ + } else { startOpenAbility(ListTemplateView.this, ChatAbility.class.getName()); } terminateAbility(); @@ -117,8 +115,6 @@ public class ListTemplateView extends LibreAbility { setOfflineTemplate(false); return; } - HttpAction action = new HttpGetTemplatesAction(this); - action.execute(); } public void saveAllData(String instanceId, String instanceName, int id) { @@ -138,7 +134,7 @@ public class ListTemplateView extends LibreAbility { return items; } - static class ListAdapter extends BaseItemProvider { + static class ListAdapter extends BaseItemProvider { private final Ability mAbility; private final LayoutScatter mInflater; @@ -205,7 +201,6 @@ public class ListTemplateView extends LibreAbility { } - public static void setOfflineTemplate(boolean offlineTemplate) { ListTemplateView.offlineTemplate = offlineTemplate; } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java deleted file mode 100644 index 95df90e..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.util.AsyncTask; -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; - -public abstract class HttpAction extends AsyncTask { - protected Ability ability; - protected Exception exception; - - public HttpAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } - - /** - * startOpenAbility - * - * @param ability - * @param name - */ - public void startOpenAbility(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbility(intent); - } - - public Intent getIntent(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - return intent; - } - - /** - * startOpenAbilityForResult - * - * @param ability - * @param name - * @param requestCode - */ - public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbilityForResult(intent, requestCode); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java deleted file mode 100644 index ec2ae66..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; -import ohos.app.Context; - -public class HttpCreateUserAction extends HttpUIResultAction { - UserConfig config; - - public HttpCreateUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - doInBackground(); - } - - // @Override - protected void doInBackground() { - try { - this.config = MainAbility.getConnection().create(ability, this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - - if (this.exception != null) { - return; - } - try { - MainAbility.setUser(config); - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - removeDialog(); - return; - } - - } - - - public void onPostExecute(String xml) { - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java deleted file mode 100644 index d1f5b21..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java +++ /dev/null @@ -1,119 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.ChannelConfig; -import org.botlibre.sdk.config.DomainConfig; -import org.botlibre.sdk.config.ForumConfig; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import org.botlibre.sdk.util.PreferencesUtils; - -import static org.botlibre.sdk.MainAbility.*; - -public class HttpFetchAction extends HttpUIResultAction { - WebMediumConfig config; - boolean launch; - - public HttpFetchAction(Ability ability, WebMediumConfig config) { - super(ability); - this.config = config; - } - - public HttpFetchAction(Ability ability, WebMediumConfig config, boolean launch) { - super(ability); - this.config = config; - this.launch = launch; - doInBackground(); - } - - public void doInBackground() { - loadingDialog(); - try { - this.config = getConnection().fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - onPostExecute(); - } - - @SuppressWarnings("rawtypes") -// @Override - public void onPostExecute() { -// super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - setInstance(config); - - Preferences cookies = PreferencesUtils.getPreferences(this.ability); - cookies.putString(this.config.getType(), this.config.name); - cookies.flushSync(); - - Class childAbility = getAbility(this.config); - if (this.launch && !this.config.isExternal) { - if (this.config instanceof ChannelConfig) { - } else if (this.config instanceof InstanceConfig) { - } else if (this.config instanceof DomainConfig) { - getConnection().setDomain((DomainConfig) this.config); - setDomain((DomainConfig) this.config); - setTags(null); - setCategories(null); - setForumTags(null); - setForumCategories(null); - setChannelTags(null); - setChannelCategories(null); - setDomainTags(null); - setDomainCategories(null); - setGraphicTags(null); - setGraphicCategories(null); - - setType(getDefaultType()); - - startOpenAbility(this.ability, MainAbility.class.getName()); - return; - } else if (this.config instanceof ForumConfig) { - BrowseConfig config = new BrowseConfig(); - - config.typeFilter = "Public"; - config.type = "Post"; - config.instance = getInstance().id; - config.sort = "date"; - return; - } - } else { - if (this.config instanceof InstanceConfig) { - } - } - startOpenAbility(this.ability, childAbility.getName()); - } catch (Exception error) { - this.exception = error; - error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java deleted file mode 100644 index 9f857eb..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFlagUserAction extends HttpUIAction { - UserConfig config; - - public HttpFlagUserAction(Ability ability, UserConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().flag(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java deleted file mode 100644 index c597e18..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import java.util.List; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import org.botlibre.sdk.config.AvatarMedia; -import ohos.aafwk.ability.Ability; - -public class HttpGetAvatarMediaAction extends HttpUIAction { - AvatarConfig config; - List instances; - boolean finish = false; - - public HttpGetAvatarMediaAction(Ability ability, AvatarConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.instances = MainAbility.getConnection().getAvatarMedia(config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setAvatarMedias(instances); - if (this.finish) { - this.ability.terminateAbility(); - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java deleted file mode 100644 index 8866e8e..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpGetInstancesAction extends HttpUIResultAction { - - boolean finish = false; - - public HttpGetInstancesAction(Ability ability, BrowseConfig config) { - super(ability); - doInBackground(); - } - - public HttpGetInstancesAction(Ability ability, BrowseConfig config, boolean finish) { - super(ability); - this.finish = finish; - doInBackground(); - } - - public void doInBackground(){ - loadingDialog(); - onPostExecute(); - } - - public void onPostExecute() { - if (this.exception != null) { - return; - } - - if (this.finish) { - this.ability.terminateAbility(); - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java deleted file mode 100644 index b2dd10c..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetLearningAction.java +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.InstanceConfig; -import org.botlibre.sdk.config.LearningConfig; -import ohos.aafwk.ability.Ability; - -public class HttpGetLearningAction extends HttpUIAction { - InstanceConfig config; - LearningConfig learning; - - public HttpGetLearningAction(Ability Ability, InstanceConfig config) { - super(Ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.learning = MainAbility.getConnection().getLearning(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.setLearning(learning); - -// ((LearningAbility)this.ability).resetView(); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java deleted file mode 100644 index 5152e0f..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.InstanceConfig; -import ohos.aafwk.ability.Ability; - -import javax.swing.text.html.ListView; -import java.util.List; - -public class HttpGetTemplatesAction extends HttpAction { - - - public HttpGetTemplatesAction(Ability Ability) { - super(Ability); - - } - - @Override - protected String doInBackground(Void... params) { - return ""; - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java deleted file mode 100644 index 17f5e17..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java +++ /dev/null @@ -1,75 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; - -public abstract class HttpResultAction { - protected Ability ability; - protected Exception exception; - - public HttpResultAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } - - /** - * 启动ability - * - * @param ability - * @param name - */ - public void startOpenAbility(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbility(intent); - } - - /** - * 启动ability - * - * @param ability - * @param name - * @param requestCode - */ - public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbilityForResult(intent, requestCode); - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java deleted file mode 100644 index 43ef52f..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java +++ /dev/null @@ -1,72 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.util.LogUtils; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; - -import java.util.Optional; - -public abstract class HttpUIAction extends HttpAction { - protected CommonDialog dialog; - - public HttpUIAction(Ability Ability) { - super(Ability); - } - - // 加载 - public void loadingDialog() { - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100, 150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } - - public void removeDialog() { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java deleted file mode 100644 index b79ac22..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.ResUtils; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; - -import java.util.Optional; - -public abstract class HttpUIResultAction extends HttpResultAction { - protected CommonDialog dialog; - - public HttpUIResultAction(Ability Ability) { - super(Ability); - } - - // 加载 - public void loadingDialog() { - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100, 150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } - - public void removeDialog() { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1, ResUtils.getString(ability, ResourceTable.String_exception), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java deleted file mode 100644 index d5bfb5a..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.botlibre.sdk.ability.war; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ability.actions.HttpUIAction; -import org.botlibre.sdk.config.InstanceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpChatWarAction extends HttpUIAction { - ChatWarConfig config; - InstanceConfig instance; - - public HttpChatWarAction(Ability ability, ChatWarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - InstanceConfig instance = new InstanceConfig(); - this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setInstance(instance); - } - -} \ No newline at end of file diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java index 4fe4f10..992d34e 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java @@ -28,7 +28,6 @@ import ohos.data.preferences.Preferences; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; import org.botlibre.sdk.ability.LibreAbility; -import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.WebMediumConfig; @@ -48,6 +47,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi private static InstanceConfig bot2; private String topic = "Hello"; public boolean handsFreeSpeechWAS; + private InstanceConfig instance; private static long SECRET = 4357845875643L; @@ -93,8 +93,20 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi config.looser = looser.id; config.topic = topic; config.secret = String.valueOf(SECRET + MainAbility.getUser().user.length()); - HttpChatWarAction action = new HttpChatWarAction(this, config); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + InstanceConfig instance = new InstanceConfig(); + instance=(InstanceConfig) MainAbility.getConnection().custom("chat-war", config, instance); + InstanceConfig finalInstance = instance; + runUI(new Runnable() { + @Override + public void run() { + MainAbility.setInstance(finalInstance); + } + }); + } + }); } catch (Exception e) { MainAbility.showMessage("You must be signed in to vote!", this); } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ApplicationJumpUtil.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ApplicationJumpUtil.java index 2307ffb..fae7a8f 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ApplicationJumpUtil.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ApplicationJumpUtil.java @@ -194,6 +194,5 @@ public class ApplicationJumpUtil { mIntent.setOperation(operation); context.startAbility(mIntent); } - } } diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java deleted file mode 100644 index 3b8c833..0000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.util; - -import ohos.eventhandler.EventHandler; -import ohos.eventhandler.EventRunner; -import ohos.eventhandler.InnerEvent; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; -import java.util.concurrent.FutureTask; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * MyAsyncTask - * - * @param - * @param - * @param - * @since 2021-05-08 - */ -public abstract class AsyncTask { - private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); - private static final int CORE_COUNT = CPU_COUNT + 1; - private static final int MAX_COUNT = CPU_COUNT * 2 + 1; - private static final int POST_EXECUTE = 0x00001; - private static final int PUBLISH_PROGRSS = 0x00002; - private static final int KEEP_ALIVE = 1; - private static final BlockingQueue POOLWORKQUEUE = - new LinkedBlockingQueue(128); - private static final ThreadFactory STHREADFACTORY = new ThreadFactory() { - private final AtomicInteger mCount = new AtomicInteger(1); - - /** - * newThread - * - * @param r runnable - * @return re - */ - public Thread newThread(Runnable r) { - return new Thread(r, "AsyncTask #" + mCount.getAndIncrement()); - } - }; - private static final Executor MEXECUTOR = new ThreadPoolExecutor(CORE_COUNT, MAX_COUNT, KEEP_ALIVE, - TimeUnit.SECONDS, POOLWORKQUEUE, STHREADFACTORY); - - private static InnerUiHandler mUIHandler; - private final WorkRunnable mWork; - private final FutureTask mFutureTask; - private volatile Status mStatus = Status.PENDING; - - /** - * 构造函数 - */ - public AsyncTask() { - /** - * 构造函数中初始化 - */ - mWork = new WorkRunnable() { - /** - * call - * - * @return re - * @throws Exception - */ - @Override - public Result call() throws Exception { - Result result = doInBackground(paramses); - return result; - } - }; - /** - * 构造函数中初始化 - */ - mFutureTask = new FutureTask(mWork) { - @Override - protected void done() { - super.done(); - try { - postResult(super.get()); - } catch (InterruptedException | ExecutionException e) { - e.getMessage(); - } - } - }; - } - - private static EventHandler getHandler() { - synchronized (AsyncTask.class) { - if (mUIHandler == null) { - mUIHandler = new InnerUiHandler(); - } - return mUIHandler; - } - } - - - /** - * 用来获取futuretask执行完成的结果 - * - * @return result - * @throws InterruptedException - * @throws ExecutionException - */ - public final Result get() throws InterruptedException, ExecutionException { - return mFutureTask.get(); - } - - private void postResult(Result result) { - getHandler().sendEvent(InnerEvent.get(POST_EXECUTE)); - } - - /** - * 可以回调的一些函数 - */ - protected void onPreExecute() { - } - - /** - * doInBackground - * - * @param params params - * @return result - */ - protected abstract Result doInBackground(Params[] params); - - /** - * onPostExecute - * - * @param result result - */ - protected void onPostExecute(Result result) { - } - - /** - * onCancelled - */ - protected void onCancelled() { - } - - /** - * onProgressUpdate - * - * @param progress progress - */ - protected void onProgressUpdate(Progress[] progress) { - } - - /** - * InnerUiHandler - * - * @since 2021-04-25 - */ - private static class InnerUiHandler extends EventHandler { - InnerUiHandler() { - super(EventRunner.getMainEventRunner()); - } - - @Override - protected void processEvent(InnerEvent event) { - super.processEvent(event); - switch (event.eventId) { - case POST_EXECUTE: - AsyncTaskResult result = (AsyncTaskResult) event.object; - result.myAsyncTask.postResult(result.mData); - break; - case PUBLISH_PROGRSS: - AsyncTaskResult result2 = (AsyncTaskResult) event.object; - result2.myAsyncTask.onProgressUpdate(result2.mData); - break; - default: - break; - } - } - } - - /** - * publishProgress - * - * @param progress progress - */ - public final void publishProgress(Progress... progress) { - getHandler().sendEvent(InnerEvent.get(PUBLISH_PROGRSS, - new AsyncTaskResult(this, progress))); - } - - /** - * InnerUiHandler - * - * @since 2021-04-25 - */ - public enum Status { - /** - * Indicates that the task has not been executed yet. - */ - PENDING, - /** - * Indicates that the task is running. - */ - RUNNING, - /** - * Indicates that {@link AsyncTask#onPostExecute} has finished. - */ - FINISHED, - } - - /** - * execute - * - * @param params params - * @return async - */ - public final AsyncTask execute(Params... params) { - return executeOnExecutor(MEXECUTOR, params); - } - - /** - * executeOnExecutor - * - * @param executor executor - * @param paramses paramses - * @return async - * @throws IllegalStateException - */ - public final AsyncTask executeOnExecutor(Executor executor, Params[] paramses) { - if (mStatus != Status.PENDING) { - switch (mStatus) { - case RUNNING: - - throw new IllegalStateException("Cannot execute task:" - + " the task is already running."); - case FINISHED: - throw new IllegalStateException("Cannot execute task:" - + " the task has already been executed " - + "(a task can be executed only once)"); - default: - break; - } - } - - mStatus = Status.RUNNING; - onPreExecute(); - mWork.paramses = paramses; - executor.execute(mFutureTask); - return this; - } - - /** - * InnerUiHandler - * - * @param paramses - * @param result - * @since 2021-04-25 - */ - private abstract static class WorkRunnable implements Callable { - /** - * execute - */ - Params[] paramses; - } - - /** - * InnerUiHandler - * - * @param data - * @since 2021-04-25 - */ - private static class AsyncTaskResult { - AsyncTask myAsyncTask; - Data[] mData; - - AsyncTaskResult(AsyncTask myAsyncTask, Data[] data) { - this.myAsyncTask = myAsyncTask; - this.mData = data; - } - } - -} diff --git a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java index 0117f4c..dc514a4 100644 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java +++ b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java @@ -15,6 +15,7 @@ package org.botlibre.sdk.util; +import org.botlibre.sdk.ResourceTable; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; import ohos.agp.components.LayoutScatter; @@ -22,7 +23,7 @@ import ohos.agp.components.Text; import ohos.agp.utils.LayoutAlignment; import ohos.agp.window.dialog.ToastDialog; import ohos.app.Context; -import org.botlibre.sdk.ResourceTable; + /** * ToastUtils diff --git a/BotLibreOffline/entry/src/ohosTest/java/org/botlibre/sdk/MainAbilityTest.java b/BotLibreOffline/entry/src/ohosTest/java/org/botlibre/sdk/MainAbilityTest.java deleted file mode 100644 index 744d2f4..0000000 --- a/BotLibreOffline/entry/src/ohosTest/java/org/botlibre/sdk/MainAbilityTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; -import ohos.hiviewdfx.HiLog; -import ohos.hiviewdfx.HiLogLabel; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.ResUtils; -import org.junit.Assert; -import org.junit.Test; - -/** - * 单元测试类 - * - * @since 2021-05-25 - */ -public class MainAbilityTest { - private static final HiLogLabel LABEL_LOG = new HiLogLabel(10043, 0xD000f00, "MainAbility"); - Ability ability = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility(); - - @Test - public void onActive() { - LogUtils.d("HiLog","单元测试"); - int pxTovp = ResUtils.pxTovp(ability.getApplicationContext(),1); - Assert.assertEquals(0, pxTovp); - int height = ResUtils.getScreenHeight(ability.getApplicationContext()); - HiLog.info(LABEL_LOG,height + ""); - int width = ResUtils.getScreenWidth(ability.getApplicationContext()); - HiLog.info(LABEL_LOG,width + ""); - int color = ResUtils.getColor(ability.getApplicationContext(),-65536); - HiLog.info(LABEL_LOG,color + ""); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java index 16c4bba..4686a41 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java @@ -20,8 +20,8 @@ import ohos.agp.components.Button; import ohos.agp.components.Checkbox; import ohos.agp.components.Component; import ohos.agp.components.TextField; +import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpCreateUserAction; import org.botlibre.sdk.config.UserConfig; /** @@ -66,9 +66,15 @@ public class CreateUserAbility extends LibreAbility { config.bio = text.getText().toString().trim(); Checkbox checkbox = (Checkbox) findComponentById(ResourceTable.Id_showNameCheckBox); config.showName = checkbox.isChecked(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().create(CreateUserAbility.this, config); + MainAbility.setUser(config); + terminateAbility(); - HttpCreateUserAction action = new HttpCreateUserAction(getContext(), this, config); - action.execute(); + } + }); } /** diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index 4bea315..9753d18 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -66,7 +66,7 @@ public abstract class LibreAbility extends Ability { /** * 主线程执行任务 * - * @param runnable + * @param runnable run */ public static void runUi(Runnable runnable) { EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner()); @@ -74,4 +74,14 @@ public abstract class LibreAbility extends Ability { } + /** + * 子线程执行任务 + * + * @param runnable run + */ + public static void runWork(Runnable runnable) { + EventRunner runner = EventRunner.create(true); + EventHandler eventHandler = new EventHandler(runner); + eventHandler.postTask(runnable, 0, EventHandler.Priority.IMMEDIATE); + } } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index d06ae1a..07d514d 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java @@ -19,9 +19,12 @@ import ohos.aafwk.content.Intent; import ohos.agp.components.Button; import ohos.agp.components.Component; import ohos.agp.components.TextField; +import ohos.data.preferences.Preferences; +import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpConnectAction; import org.botlibre.sdk.config.UserConfig; +import org.botlibre.sdk.util.PreferencesUtils; + /** * Ability for user login. @@ -51,8 +54,23 @@ public class LoginAbility extends LibreAbility implements Component.ClickedListe UserConfig config = new UserConfig(); config.user = user; config.password = password; - HttpConnectAction action = new HttpConnectAction(this, config, true); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().connect(config); + runUi(new Runnable() { + @Override + public void run() { + MainAbility.setUser(config); + Preferences cookies = PreferencesUtils.getPreferences(LoginAbility.this); + cookies.putString("user", MainAbility.getUser().user); + cookies.putString("token", MainAbility.getUser().token); + cookies.flushSync(); + terminateAbility(); + } + }); + } + }); } public void signUp() { diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java deleted file mode 100644 index f3eab37..0000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; -import org.botlibre.sdk.util.AsyncTask; - -/** - * HttpConnectAction - * - * @since 2021-04-16 - */ -public abstract class HttpAction extends AsyncTask { - protected Ability ability; - protected Exception exception; - - /** - * HttpAction - * - * @param ability - */ - public HttpAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } - - /** - * getIntent - * - * @param abilit - * @param name - * @param requestCode - */ - public void startOpenAbilityForResult(Ability abilit, String name, int requestCode) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(abilit.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - abilit.startAbilityForResult(intent, requestCode); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java deleted file mode 100644 index e0147b7..0000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import org.botlibre.sdk.util.PreferencesUtils; - -/** - * HttpConnectAction - * - * @since 2021-04-16 - */ -public class HttpConnectAction extends HttpUIAction { - UserConfig config; - boolean finish; - - /** - * HttpConnectAction - * - * @param ability - * @param config - * @param finish - */ - public HttpConnectAction(Ability ability, UserConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - } - - @Override - protected String doInBackground(Void... params) { - this.config = MainAbility.getConnection().connect(config); - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setUser(this.config); - if (this.ability instanceof MainAbility) { - ((MainAbility) this.ability).resetView(); - } - - if (this.finish) { - - Preferences cookies = PreferencesUtils.getPreferences(ability); - cookies.putString("user", MainAbility.getUser().user); - cookies.putString("token", MainAbility.getUser().token); - cookies.flushSync(); - - this.ability.terminateAbility(); - } - } - -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java deleted file mode 100644 index 8322d34..0000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; -import ohos.app.Context; - -/** - * HttpConnectAction - * - * @since 2021-04-16 - */ -public class HttpCreateUserAction extends HttpUIAction { - UserConfig config; - - /** - * HttpCreateUserAction - * - * @param context - * @param ability - * @param config - */ - public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { - super(ability); - this.config = config; - // this.context = context; - } - - @Override - protected String doInBackground(Void... params) { - this.config = MainAbility.getConnection().create(ability, this.config); - if (this.exception != null) { - return ""; - } - MainAbility.setUser(this.config); - this.ability.terminateAbility(); - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java deleted file mode 100644 index d9c4cbf..0000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.util.LogUtils; - -import java.util.Optional; - -/** - * HttpConnectAction - * - * @since 2021-04-16 - */ -public abstract class HttpUIAction extends HttpAction { - protected CommonDialog dialog; - - public HttpUIAction(Ability Ability) { - super(Ability); - } - - @Override - protected void onPreExecute() { - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100, 150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } - - @Override - protected void onPostExecute(String result) { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } - - public void removeDialog() { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } -} \ No newline at end of file diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java index 593b2e5..33d2928 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java @@ -30,8 +30,6 @@ import java.util.Map; */ public class AvatarConfig extends WebMediumConfig { public Map mediaConfig; - private String avatarFormat; - private boolean avatarHD; public String background; public String icon; @@ -43,140 +41,6 @@ public class AvatarConfig extends WebMediumConfig { mediaConfig = new HashMap(); } - public ChatResponse chatReply(ChatResponse chat) { - String emotion = MicroConnection.getBot().mood().currentEmotionalState().name(); - String action = MicroConnection.getBot().avatar().getAction(); - String pose = MicroConnection.getBot().avatar().getPose(); - if (this.getBackground() != null) { - String background = this.getBackground(); - chat.avatarBackground = background; - } - List matching = null; - - // Audio - if (action != null) { - matching = this.getAudio(action, pose); - if (!matching.isEmpty()) { - AvatarMedia media = Utils.random(matching); - String[] array = media.media.split("\\."); - chat.avatarActionAudio = media.mediaId + "." + array[1]; - chat.avatarActionAudioType = media.getType(); - } - } - matching = this.getAudio("", pose); - if (!matching.isEmpty()) { - AvatarMedia media = Utils.random(matching); - String[] array = media.media.split("\\."); - chat.avatarAudio = media.mediaId + "." + array[1]; - chat.avatarAudioType = media.getType(); - } - // Image/video - if (action != null) { - matching = this.getMedia(emotion, action, pose, ""); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatarAction = media.mediaId + "." + array[1]; - } - } - matching = this.getMedia(emotion, "", pose, ""); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatar = media.mediaId + "." + array[1]; - chat.avatar2 = null; - chat.avatar3 = null; - chat.avatar4 = null; - chat.avatar5 = null; - if (matching.size() > 1) { - AvatarMedia media2 = randomMatch(matching); - AvatarMedia media3 = randomMatch(matching); - AvatarMedia media4 = randomMatch(matching); - AvatarMedia media5 = randomMatch(matching); - if (media != media2 || media != media3 || media != media4 || media != media5) { - array = media2.media.split("\\."); - chat.avatar2 = media2.mediaId + "." + array[1]; - array = media3.media.split("\\."); - chat.avatar3 = media3.mediaId + "." + array[1]; - array = media4.media.split("\\."); - chat.avatar4 = media4.mediaId + "." + array[1]; - array = media5.media.split("\\."); - chat.avatar5 = media5.mediaId + "." + array[1]; - } - } - chat.avatarType = media.getType(); - } - matching = this.getMedia(emotion, "", pose, "talking"); - if (!matching.isEmpty()) { - AvatarMedia media = randomMatch(matching); - String[] array = media.media.split("\\."); - chat.avatarTalk = media.mediaId + "." + array[1]; - chat.avatarTalkType = media.getType(); - } - return chat; - } - -// public String getDefaultAvatarMediaOne(){ -// String name = null; -// for (AvatarMedia media: mediaConfig.values()) { -// if(!media.talking && media.hd && media.name.contains("blink") && media.poses.equals("") && media.emotions.equals("")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId+"."+array[1]; -// type = media.type; -// } -// } -// return name; -// } -// public String getDefaultAvatarMediaTwo(){ -// String name = null; -// for (AvatarMedia media: mediaConfig.values()) { -// if(!media.talking && media.hd && media.name.contains("blink") && media.emotions.contains("HAPPY")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId+"."+array[1]; -// type = media.type; -// } -// } -// return name; -// } -// -// public String getDefaultAvatarMediaThree(){ -// String name = null; -// for (AvatarMedia media: mediaConfig.values()) { -// if(!media.talking && media.hd && media.name.contains("blink") && media.emotions.contains("ANGER")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId+"."+array[1]; -// type = media.type; -// } -// } -// return name; -// } -// public String getDefaultAvatarMediaFour(){ -// String name = null; -// for (AvatarMedia media: mediaConfig.values()) { -// if(!media.talking && media.hd && media.name.contains("blink") && media.emotions.equals("") && media.poses.contains("sleeping")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId+"."+array[1]; -// type = media.type; -// } -// } -// return name; -// } -// public String getTalkingAvatarMedia(){ -// String name = null; -// for(AvatarMedia media : mediaConfig.values()){ -// if(media.talking && media.hd && media.name.contains("talk")){ -// String[] array = media.media.split("\\."); -// name = media.mediaId +"."+ array[1]; -// type = media.type; -// } -// } -// return name; -// } -// -// public String getTypeAvatarMedia(){ -// return type; -// } - public WebMediumConfig credentials() { AvatarConfig config = new AvatarConfig(); config.id = this.id; @@ -550,50 +414,6 @@ public class AvatarConfig extends WebMediumConfig { return matches; } - public AvatarMedia randomMatch(List matches) { - List formatMatches = new ArrayList(); - String format = "mp4"; - if (this.avatarFormat != null && !this.avatarFormat.isEmpty()) { - format = this.avatarFormat; - } - for (AvatarMedia media : matches) { - if (media.getType().indexOf(format) != -1) { - formatMatches.add(media); - } - } - if (formatMatches.isEmpty()) { - List hdMatches = new ArrayList(); - for (AvatarMedia media : matches) { - if (this.avatarHD && media.getHD()) { - hdMatches.add(media); - } else if (!this.avatarHD && !media.getHD()) { - hdMatches.add(media); - } - } - if (!hdMatches.isEmpty()) { - return Utils.random(hdMatches); - } - return Utils.random(matches); - } else { - List hdMatches = new ArrayList(); - for (AvatarMedia media : formatMatches) { - if (this.avatarHD && media.getHD()) { - hdMatches.add(media); - } else if (!this.avatarHD && !media.getHD()) { - hdMatches.add(media); - } - } - if (!hdMatches.isEmpty()) { - return Utils.random(hdMatches); - } - return Utils.random(formatMatches); - } - } - - public String getBackground() { - return background; - } - public String getIcon() { return icon; } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java index b53a7b9..21e553d 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ChatResponse.java @@ -15,10 +15,11 @@ package org.botlibre.sdk.config; -import ohos.utils.zson.ZSONException; -import ohos.utils.zson.ZSONObject; import org.w3c.dom.Element; import org.w3c.dom.Node; +import ohos.utils.zson.ZSONException; +import ohos.utils.zson.ZSONObject; + /** * DTO for XML chat config. diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java index 423d0a1..1b92967 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ResponseConfig.java @@ -15,14 +15,14 @@ package org.botlibre.sdk.config; -import ohos.utils.zson.ZSONException; -import ohos.utils.zson.ZSONObject; +import java.io.StringWriter; +import java.util.Objects; + import org.botlibre.util.Utils; import org.w3c.dom.Element; import org.w3c.dom.Node; - -import java.io.StringWriter; -import java.util.Objects; +import ohos.utils.zson.ZSONException; +import ohos.utils.zson.ZSONObject; /** diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java index c16c238..68d9b51 100644 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java +++ b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/config/ScriptSourceConfig.java @@ -85,23 +85,4 @@ public class ScriptSourceConfig extends Config { } } - public String getNextVersion() { - if (this.source == null) { - return "0.1"; - } - - String version = this.source; - int index = version.lastIndexOf('.'); - if (index != -1) { - String major = version.substring(0, index); - String minor = version.substring(index + 1, version.length()); - try { - int value = Integer.valueOf(minor); - version = major + "." + (value + 1); - } catch (NumberFormatException ignore) { - } - } - return version; - } - } diff --git a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java deleted file mode 100644 index 3b8c833..0000000 --- a/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk.util; - -import ohos.eventhandler.EventHandler; -import ohos.eventhandler.EventRunner; -import ohos.eventhandler.InnerEvent; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; -import java.util.concurrent.FutureTask; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * MyAsyncTask - * - * @param - * @param - * @param - * @since 2021-05-08 - */ -public abstract class AsyncTask { - private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); - private static final int CORE_COUNT = CPU_COUNT + 1; - private static final int MAX_COUNT = CPU_COUNT * 2 + 1; - private static final int POST_EXECUTE = 0x00001; - private static final int PUBLISH_PROGRSS = 0x00002; - private static final int KEEP_ALIVE = 1; - private static final BlockingQueue POOLWORKQUEUE = - new LinkedBlockingQueue(128); - private static final ThreadFactory STHREADFACTORY = new ThreadFactory() { - private final AtomicInteger mCount = new AtomicInteger(1); - - /** - * newThread - * - * @param r runnable - * @return re - */ - public Thread newThread(Runnable r) { - return new Thread(r, "AsyncTask #" + mCount.getAndIncrement()); - } - }; - private static final Executor MEXECUTOR = new ThreadPoolExecutor(CORE_COUNT, MAX_COUNT, KEEP_ALIVE, - TimeUnit.SECONDS, POOLWORKQUEUE, STHREADFACTORY); - - private static InnerUiHandler mUIHandler; - private final WorkRunnable mWork; - private final FutureTask mFutureTask; - private volatile Status mStatus = Status.PENDING; - - /** - * 构造函数 - */ - public AsyncTask() { - /** - * 构造函数中初始化 - */ - mWork = new WorkRunnable() { - /** - * call - * - * @return re - * @throws Exception - */ - @Override - public Result call() throws Exception { - Result result = doInBackground(paramses); - return result; - } - }; - /** - * 构造函数中初始化 - */ - mFutureTask = new FutureTask(mWork) { - @Override - protected void done() { - super.done(); - try { - postResult(super.get()); - } catch (InterruptedException | ExecutionException e) { - e.getMessage(); - } - } - }; - } - - private static EventHandler getHandler() { - synchronized (AsyncTask.class) { - if (mUIHandler == null) { - mUIHandler = new InnerUiHandler(); - } - return mUIHandler; - } - } - - - /** - * 用来获取futuretask执行完成的结果 - * - * @return result - * @throws InterruptedException - * @throws ExecutionException - */ - public final Result get() throws InterruptedException, ExecutionException { - return mFutureTask.get(); - } - - private void postResult(Result result) { - getHandler().sendEvent(InnerEvent.get(POST_EXECUTE)); - } - - /** - * 可以回调的一些函数 - */ - protected void onPreExecute() { - } - - /** - * doInBackground - * - * @param params params - * @return result - */ - protected abstract Result doInBackground(Params[] params); - - /** - * onPostExecute - * - * @param result result - */ - protected void onPostExecute(Result result) { - } - - /** - * onCancelled - */ - protected void onCancelled() { - } - - /** - * onProgressUpdate - * - * @param progress progress - */ - protected void onProgressUpdate(Progress[] progress) { - } - - /** - * InnerUiHandler - * - * @since 2021-04-25 - */ - private static class InnerUiHandler extends EventHandler { - InnerUiHandler() { - super(EventRunner.getMainEventRunner()); - } - - @Override - protected void processEvent(InnerEvent event) { - super.processEvent(event); - switch (event.eventId) { - case POST_EXECUTE: - AsyncTaskResult result = (AsyncTaskResult) event.object; - result.myAsyncTask.postResult(result.mData); - break; - case PUBLISH_PROGRSS: - AsyncTaskResult result2 = (AsyncTaskResult) event.object; - result2.myAsyncTask.onProgressUpdate(result2.mData); - break; - default: - break; - } - } - } - - /** - * publishProgress - * - * @param progress progress - */ - public final void publishProgress(Progress... progress) { - getHandler().sendEvent(InnerEvent.get(PUBLISH_PROGRSS, - new AsyncTaskResult(this, progress))); - } - - /** - * InnerUiHandler - * - * @since 2021-04-25 - */ - public enum Status { - /** - * Indicates that the task has not been executed yet. - */ - PENDING, - /** - * Indicates that the task is running. - */ - RUNNING, - /** - * Indicates that {@link AsyncTask#onPostExecute} has finished. - */ - FINISHED, - } - - /** - * execute - * - * @param params params - * @return async - */ - public final AsyncTask execute(Params... params) { - return executeOnExecutor(MEXECUTOR, params); - } - - /** - * executeOnExecutor - * - * @param executor executor - * @param paramses paramses - * @return async - * @throws IllegalStateException - */ - public final AsyncTask executeOnExecutor(Executor executor, Params[] paramses) { - if (mStatus != Status.PENDING) { - switch (mStatus) { - case RUNNING: - - throw new IllegalStateException("Cannot execute task:" - + " the task is already running."); - case FINISHED: - throw new IllegalStateException("Cannot execute task:" - + " the task has already been executed " - + "(a task can be executed only once)"); - default: - break; - } - } - - mStatus = Status.RUNNING; - onPreExecute(); - mWork.paramses = paramses; - executor.execute(mFutureTask); - return this; - } - - /** - * InnerUiHandler - * - * @param paramses - * @param result - * @since 2021-04-25 - */ - private abstract static class WorkRunnable implements Callable { - /** - * execute - */ - Params[] paramses; - } - - /** - * InnerUiHandler - * - * @param data - * @since 2021-04-25 - */ - private static class AsyncTaskResult { - AsyncTask myAsyncTask; - Data[] mData; - - AsyncTaskResult(AsyncTask myAsyncTask, Data[] data) { - this.myAsyncTask = myAsyncTask; - this.mData = data; - } - } - -} diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java index 94cebc9..742bbf0 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java @@ -55,9 +55,6 @@ import ohos.utils.PacMap; import ohos.utils.zson.ZSONObject; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpAction; -import org.botlibre.sdk.ability.actions.HttpChatAction; -import org.botlibre.sdk.ability.actions.HttpFetchChatAvatarAction; import org.botlibre.sdk.config.AvatarConfig; import org.botlibre.sdk.config.ChatConfig; import org.botlibre.sdk.config.ChatResponse; @@ -676,8 +673,21 @@ public class ChatAbility extends LibreAbility { } catch (Exception exception) { } } - HttpAction action = new HttpChatAction(ChatAbility.this, config); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().chat(config); + runUI(new Runnable() { + @Override + public void run() { + try { + }catch (Exception exception){ + MainAbility.errorInfo(1, exception.getMessage(), exception, ChatAbility.this); + } + } + }); + } + }); } }; thread1.start(); @@ -802,10 +812,21 @@ public class ChatAbility extends LibreAbility { } this.messages.add(config); handler.sendEvent(LIST_CONTAINER); - - - HttpChatAction action = new HttpChatAction(ChatAbility.this, config); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().chat(config); + runUI(new Runnable() { + @Override + public void run() { + try { + }catch (Exception exception){ + MainAbility.errorInfo(1, exception.getMessage(), exception, ChatAbility.this); + } + } + }); + } + }); editText.setText(""); resetToolbar(); @@ -875,8 +896,22 @@ public class ChatAbility extends LibreAbility { } AvatarConfig avatarConfig = (AvatarConfig) this.avatar.credentials(); - HttpFetchChatAvatarAction action = new HttpFetchChatAvatarAction(this, avatarConfig); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().fetch(avatarConfig); + runUI(new Runnable() { + @Override + public void run() { + try { + } catch (Exception error) { + MainAbility.error(error.getMessage(), error, ChatAbility.this); + return; + } + } + }); + } + }); } MainAbility.setBrowsing(false); if (this.changingVoice) { @@ -922,8 +957,21 @@ public class ChatAbility extends LibreAbility { config.conversation = MainAbility.getConversation(); config.disconnect = true; - HttpChatAction action = new HttpChatAction(this, config); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + MainAbility.getConnection().chat(config); + runUI(new Runnable() { + @Override + public void run() { + try { + }catch (Exception exception){ + MainAbility.errorInfo(1, exception.getMessage(), exception, ChatAbility.this); + } + } + }); + } + }); } muteMicBeep(false); if (ttsClient != null) { diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java index a986d14..9da3795 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java @@ -25,7 +25,6 @@ import ohos.agp.components.Component; import ohos.utils.net.Uri; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.ChannelConfig; import org.botlibre.sdk.config.ForumConfig; diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java index b8c488b..e811c00 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LibreAbility.java @@ -21,6 +21,8 @@ package org.botlibre.sdk.ability; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; /** * Generic Ability for common behavior. @@ -42,4 +44,25 @@ public abstract class LibreAbility extends Ability { intent.setOperation(operation); startAbility(intent); } + + /** + * runUI + * + * @param runnable run + */ + public static void runUI(Runnable runnable) { + EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner()); + eventHandler.postSyncTask(runnable); + } + + /** + * 子线程执行任务 + * + * @param runnable run + */ + public static void runWork(Runnable runnable) { + EventRunner runner = EventRunner.create(true); + EventHandler eventHandler = new EventHandler(runner); + eventHandler.postTask(runnable, 0, EventHandler.Priority.IMMEDIATE); + } } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index 9b024b9..0af9355 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java @@ -18,13 +18,12 @@ package org.botlibre.sdk.ability; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.ability.actions.HttpConnectAction; -import org.botlibre.sdk.config.UserConfig; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; import ohos.agp.components.Component; import ohos.agp.components.TextField; +import org.botlibre.sdk.ResourceTable; +import org.botlibre.sdk.config.UserConfig; /** * Ability for user login. diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java deleted file mode 100644 index 8b7fb90..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java +++ /dev/null @@ -1,94 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.util.AsyncTask; -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; - -public abstract class HttpAction extends AsyncTask { - protected Ability ability; - protected Exception exception; - - public HttpAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } - - /** - * 启动Ability - * - * @param ability Ability - * @param name String - */ - public void startOpenAbility(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbility(intent); - } - - /** - * getIntent - * - * @param ability - * @param name - * @return ddd - */ - public Intent getIntent(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - return intent; - } - - /** - * 启动Ability - * - * @param ability - * @param name - * @param requestCode - */ - public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbilityForResult(intent, requestCode); - } -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java deleted file mode 100644 index 80fac96..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java +++ /dev/null @@ -1,163 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.ChatConfig; -import org.botlibre.sdk.config.ChatResponse; -import ohos.aafwk.ability.Ability; - - -public class HttpChatAction extends HttpAction { - ChatConfig config; - - public HttpChatAction(Ability ability, ChatConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - MainAbility.getConnection().chat(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPreExecute() { - if (!this.config.disconnect) { - super.onPreExecute(); - } - } - - @Override - protected void onPostExecute(String xml) { - if (this.config.disconnect) { - return; - } - super.onPostExecute(xml); - if (this.exception != null) { - MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); - return; - } - try { -// MainAbility.conversation = this.response.conversation; -// final ChatAbility Ability = (ChatAbility)this.ability; -// -// Image imageView = (Image)Ability.imageView; -// final VideoView videoView = Ability.videoView; -// Component videoLayout = Ability.videoLayout; -// -// if (MainAbility.sound && this.response.avatarActionAudio != null && this.response.avatarActionAudio.length() > 0) { -// // Action audio -// if (MainAbility.online) { -// Ability.playAudio(this.response.avatarActionAudio, false, true, true); -// } -// } -// if (MainAbility.sound && this.response.avatarAudio != null && this.response.avatarAudio.length() > 0) { -// Ability.music = true; -// // Background audio -// if (!this.response.avatarAudio.equals(Ability.currentAudio)) { -// if (Ability.audioPlayer != null) { -// Ability.audioPlayer.stop(); -// Ability.audioPlayer.release(); -// } -// if (MainAbility.online) { -// Ability.audioPlayer = Ability.playAudio(this.response.avatarAudio, true, true, true); -// } -// //making sure the that mic is turned off while using the DeviceVoice. -// ChatAbility.micLastStat = false; -// } -// } else if (Ability.audioPlayer != null) { -// Ability.audioPlayer.stop(); -// Ability.audioPlayer.release(); -// Ability.audioPlayer = null; -// Ability.music = false; -// } -// -// if (!MainAbility.disableVideo && !Ability.videoError && this.response.isVideo()) { -// // Video avatar -// if (imageView.getVisibility() != View.GONE || videoLayout.getVisibility() != View.GONE) { -// if (imageView.getVisibility() == View.VISIBLE) { -// imageView.setVisibility(View.GONE); -// } -// if (videoLayout.getVisibility() == View.GONE) { -// videoLayout.setVisibility(View.VISIBLE); -// } -// } -// if (this.response.avatarAction != null && this.response.avatarAction.length() > 0) { -// // Action video -// videoView.setOnPreparedListener(new OnPreparedListener() { -// @Override -// public void onPrepared(MediaPlayer mp) { -// mp.setLooping(false); -// } -// }); -// videoView.setOnCompletionListener(new OnCompletionListener() { -// @Override -// public void onCompletion(MediaPlayer mp) { -// Ability.resetVideoErrorListener(); -// videoView.setOnCompletionListener(null); -// Ability.cycleVideo(response); -// Ability.response(response); -// } -// }); -// videoView.setOnErrorListener(new OnErrorListener() { -// @Override -// public boolean onError(MediaPlayer mp, int what, int extra) { -// Ability.resetVideoErrorListener(); -// Ability.cycleVideo(response); -// Ability.response(response); -// return true; -// } -// }); -// Ability.playVideo(this.response.avatarAction, false); -// return; -// } else { -// Ability.cycleVideo(this.response); -// } -// } else { -// // Image avatar -// if (imageView.getVisibility() != View.GONE || videoLayout.getVisibility() != View.GONE) { -// if (imageView.getVisibility() == View.GONE) { -// imageView.setVisibility(View.VISIBLE); -// } -// if (videoLayout.getVisibility() == View.VISIBLE) { -// videoLayout.setVisibility(View.GONE); -// } -// } -// if (this.response.isVideo()) { -// HttpGetImageAction.fetchImage(this.ability, ((ChatAbility)this.ability).getAvatarIcon(this.response), imageView); -// } else { -// HttpGetImageAction.fetchImage(this.ability, this.response.avatar, imageView); -// } -// } -// -// Ability.response(this.response); - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java deleted file mode 100644 index 36a291a..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpConnectAction.java +++ /dev/null @@ -1,85 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.ability.Ability; -import ohos.data.preferences.Preferences; - -public class HttpConnectAction extends HttpUIResultAction { - UserConfig config; - boolean finish; - - public HttpConnectAction(Ability ability, UserConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - doInBackground(); - } - -// @Override - public void doInBackground() { - loadingDialog(); - try { - this.config = MainAbility.getConnection().connect(config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - } - onPostExecute(); - } - -// @Override - protected void onPostExecute() { -// super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - MainAbility.setUser(this.config); - if (this.ability instanceof MainAbility) { - ((MainAbility) this.ability).resetView(); - } - - if (this.finish) { - - Preferences cookies = PreferencesUtils.getPreferences(ability); - cookies.putString("user", MainAbility.getUser().user); - cookies.putString("token", MainAbility.getUser().token); - cookies.flushSync(); - - this.ability.terminateAbility(); - } - - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - - Preferences cookies=PreferencesUtils.getPreferences(this.ability); - cookies.putString("user", null); - cookies.putString("token", null); - cookies.flushSync(); - return; - } - } - -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java deleted file mode 100644 index d38c0f5..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.UserConfig; -import ohos.aafwk.ability.Ability; -import ohos.app.Context; - -public class HttpCreateUserAction extends HttpUIResultAction { - UserConfig config; - - public HttpCreateUserAction(Context context, Ability ability, UserConfig config) { - super(ability); - this.config = config; - doInBackground(); - } - - // @Override - protected void doInBackground() { - try { - this.config = MainAbility.getConnection().create(ability, this.config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - - if (this.exception != null) { - return; - } - try { - MainAbility.setUser(this.config); - this.ability.terminateAbility(); - } catch (Exception error) { - this.exception = error; - removeDialog(); - return; - } - - } -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java deleted file mode 100644 index ab2e355..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.AvatarConfig; -import ohos.aafwk.ability.Ability; - -public class HttpFetchChatAvatarAction extends HttpUIAction { - AvatarConfig config; - - public HttpFetchChatAvatarAction(Ability ability, AvatarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - this.config = MainAbility.getConnection().fetch(this.config); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - public void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - try { - } catch (Exception error) { - this.exception = error; - MainAbility.error(this.exception.getMessage(), this.exception, this.ability); - return; - } - } - -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java deleted file mode 100644 index 65e368d..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetInstancesAction.java +++ /dev/null @@ -1,76 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.config.BrowseConfig; -import org.botlibre.sdk.config.WebMediumConfig; -import ohos.aafwk.ability.Ability; - -import java.util.List; - -public class HttpGetInstancesAction extends HttpUIResultAction { - - BrowseConfig config; - List instances; - boolean finish = false; - - public HttpGetInstancesAction(Ability ability, BrowseConfig config) { - super(ability); - this.config = config; - doInBackground(); - } - - public HttpGetInstancesAction(Ability ability, BrowseConfig config, boolean finish) { - super(ability); - this.config = config; - this.finish = finish; - doInBackground(); - } - - public HttpGetInstancesAction(Ability ability, BrowseConfig config, boolean finish, boolean CustomAvatar) { - super(ability); - this.config = config; - this.finish = finish; - } - - public void doInBackground(){ - loadingDialog(); - try { - this.instances = MainAbility.getConnection().browse(ability,config); - } catch (Exception exception) { - this.exception = exception; - removeDialog(); - return; - } - onPostExecute(); - } - - - public void onPostExecute() { - if (this.exception != null) { - return; - } - MainAbility.setInstances(this.instances); - - if (this.finish) { - this.ability.terminateAbility(); - } - } -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java deleted file mode 100644 index a71e82f..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetTemplatesAction.java +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; - -import org.botlibre.sdk.config.InstanceConfig; -import ohos.aafwk.ability.Ability; - -import javax.swing.text.html.ListView; -import java.util.List; - -public class HttpGetTemplatesAction extends HttpAction { - List templates; - - public HttpGetTemplatesAction(Ability Ability) { - super(Ability); - - } - - @Override - protected String doInBackground(Void... params) { - try { - this.templates = MainAbility.getConnection().getTemplates(); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - public void postExecute(String xml) { - if (this.exception != null) { - return; - } - - MainAbility.setTemplates(this.templates); - - } -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java deleted file mode 100644 index b3b4d6e..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpResultAction.java +++ /dev/null @@ -1,75 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; -import ohos.aafwk.content.Operation; - -public abstract class HttpResultAction{ - protected Ability ability; - protected Exception exception; - - public HttpResultAction(Ability ability) { - this.ability = ability; - } - - public Exception getException() { - return exception; - } - - public void setException(Exception exception) { - this.exception = exception; - } - - /** - * 启动Ability - * - * @param ability Ability - * @param name String - */ - public void startOpenAbility(Ability ability, String name) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbility(intent); - } - - /** - * 启动Ability - * - * @param ability Ability - * @param name String - * @param requestCode int - */ - public void startOpenAbilityForResult(Ability ability, String name, int requestCode) { - Intent intent = new Intent(); - Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName(ability.getBundleName()) - .withAbilityName(name) - .build(); - intent.setOperation(operation); - ability.startAbilityForResult(intent, requestCode); - } -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java deleted file mode 100644 index 43ef52f..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIAction.java +++ /dev/null @@ -1,72 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.util.LogUtils; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; - -import java.util.Optional; - -public abstract class HttpUIAction extends HttpAction { - protected CommonDialog dialog; - - public HttpUIAction(Ability Ability) { - super(Ability); - } - - // 加载 - public void loadingDialog() { - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100, 150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } - - public void removeDialog() { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1, this.exception.getMessage(), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java deleted file mode 100644 index b79ac22..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * - * Copyright 2014 Paphus Solutions Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -package org.botlibre.sdk.ability.actions; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ResourceTable; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.ResUtils; -import ohos.aafwk.ability.Ability; -import ohos.agp.components.DirectionalLayout; -import ohos.agp.components.LayoutScatter; -import ohos.agp.window.dialog.CommonDialog; -import ohos.agp.window.service.Display; -import ohos.agp.window.service.DisplayAttributes; -import ohos.agp.window.service.DisplayManager; - -import java.util.Optional; - -public abstract class HttpUIResultAction extends HttpResultAction { - protected CommonDialog dialog; - - public HttpUIResultAction(Ability Ability) { - super(Ability); - } - - // 加载 - public void loadingDialog() { - try { - Optional - display = DisplayManager.getInstance().getDefaultDisplay(ability.getContext()); - DisplayAttributes displayAttributes = display.get().getAttributes(); - DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability.getContext()). - parse(ResourceTable.Layout_loading_dialog, - null, false); - this.dialog = new CommonDialog(this.ability); - this.dialog.setContentCustomComponent(layout); - this.dialog.setAutoClosable(false); - this.dialog.setSize(displayAttributes.width - 100, 150); - this.dialog.show(); - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPreExecute", exception.toString()); - } - } - - public void removeDialog() { - try { - if (this.dialog != null) { - this.dialog.destroy(); - } - if (this.exception != null) { - MainAbility.errorInfo(1, ResUtils.getString(ability, ResourceTable.String_exception), this.exception, this.ability); - } - } catch (Exception exception) { - LogUtils.error("HttpUIAction.onPostExecute", exception.toString()); - } - } -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java deleted file mode 100644 index 2f0b255..0000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/HttpChatWarAction.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.botlibre.sdk.ability.war; - -import org.botlibre.sdk.MainAbility; -import org.botlibre.sdk.ability.actions.HttpUIAction; -import org.botlibre.sdk.config.InstanceConfig; -import ohos.aafwk.ability.Ability; - -public class HttpChatWarAction extends HttpUIAction { - ChatWarConfig config; - InstanceConfig instance; - - public HttpChatWarAction(Ability ability, ChatWarConfig config) { - super(ability); - this.config = config; - } - - @Override - protected String doInBackground(Void... params) { - try { - InstanceConfig instance = new InstanceConfig(); - this.instance = (InstanceConfig) MainAbility.getConnection().custom("chat-war", this.config, instance); - } catch (Exception exception) { - this.exception = exception; - } - return ""; - } - - @Override - protected void onPostExecute(String xml) { - super.onPostExecute(xml); - if (this.exception != null) { - return; - } - MainAbility.setInstance(this.instance); - } - -} \ No newline at end of file diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java index a41ecb3..8906d08 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/war/StartWarAbility.java @@ -19,20 +19,19 @@ package org.botlibre.sdk.ability.war; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.Text; +import ohos.agp.components.TextField; +import ohos.data.preferences.Preferences; import org.botlibre.sdk.MainAbility; import org.botlibre.sdk.ResourceTable; import org.botlibre.sdk.ability.LibreAbility; -import org.botlibre.sdk.ability.actions.HttpGetInstancesAction; import org.botlibre.sdk.config.BrowseConfig; import org.botlibre.sdk.config.InstanceConfig; import org.botlibre.sdk.config.WebMediumConfig; import org.botlibre.sdk.util.PreferencesUtils; -import ohos.aafwk.content.Intent; -import ohos.agp.components.Button; -import ohos.agp.components.Component; -import ohos.agp.components.Text; -import ohos.agp.components.TextField; -import ohos.data.preferences.Preferences; import java.util.ArrayList; import java.util.List; @@ -93,8 +92,19 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi config.looser = looser.id; config.topic = topic; config.secret = String.valueOf(SECRET + MainAbility.getUser().user.length()); - HttpChatWarAction action = new HttpChatWarAction(this, config); - action.execute(); + runWork(new Runnable() { + @Override + public void run() { + InstanceConfig instance = new InstanceConfig(); + MainAbility.getConnection().custom("chat-war", config, instance); + runUI(new Runnable() { + @Override + public void run() { + MainAbility.setInstance(instance); + } + }); + } + }); } catch (Exception e) { MainAbility.showMessage("You must be signed in to vote!", this); } diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java index 3b8c833..8ecbc33 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java @@ -53,11 +53,11 @@ public abstract class AsyncTask { /** * newThread * - * @param r runnable + * @param run runnable * @return re */ - public Thread newThread(Runnable r) { - return new Thread(r, "AsyncTask #" + mCount.getAndIncrement()); + public Thread newThread(Runnable run) { + return new Thread(run, "AsyncTask #" + mCount.getAndIncrement()); } }; private static final Executor MEXECUTOR = new ThreadPoolExecutor(CORE_COUNT, MAX_COUNT, KEEP_ALIVE, diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java index 0117f4c..dc514a4 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java @@ -15,6 +15,7 @@ package org.botlibre.sdk.util; +import org.botlibre.sdk.ResourceTable; import ohos.aafwk.ability.Ability; import ohos.agp.components.Component; import ohos.agp.components.LayoutScatter; @@ -22,7 +23,7 @@ import ohos.agp.components.Text; import ohos.agp.utils.LayoutAlignment; import ohos.agp.window.dialog.ToastDialog; import ohos.app.Context; -import org.botlibre.sdk.ResourceTable; + /** * ToastUtils diff --git a/SantaBot/entry/src/ohosTest/java/org/botlibre/sdk/MainAbilityTest.java b/SantaBot/entry/src/ohosTest/java/org/botlibre/sdk/MainAbilityTest.java deleted file mode 100644 index 98b1db5..0000000 --- a/SantaBot/entry/src/ohosTest/java/org/botlibre/sdk/MainAbilityTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.botlibre.sdk; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; -import ohos.hiviewdfx.HiLog; -import ohos.hiviewdfx.HiLogLabel; -import org.botlibre.sdk.util.LogUtils; -import org.botlibre.sdk.util.ResUtils; -import org.junit.Assert; -import org.junit.Test; - -/** - * 单元测试类 - * - * @since 2021-05-25 - */ -public class MainAbilityTest { - private static final HiLogLabel LABEL_LOG = new HiLogLabel(10043, 0xD000f00, "MainAbility"); - Ability ability = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility(); - - @Test - public void onStart() { - } -} \ No newline at end of file -- Gitee From 6c1012e08a5372c85202f3901320537726b7925f Mon Sep 17 00:00:00 2001 From: 258767-shengyu <1qaz2wsx> Date: Wed, 28 Jul 2021 14:04:29 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/java/org/botlibre/sdk/MainAbility.java | 1 + .../entry/src/main/java/org/botlibre/sdk/MainAbility.java | 5 +++-- SantaBot/entry/src/main/resources/base/element/string.json | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java index ed62b43..8e93850 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java @@ -1742,6 +1742,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag config.type = "Graphic"; } config.contentRating = MainAbility.contentRating; + MainAbility.error(getString(ResourceTable.String_exception), new Exception(), MainAbility.this); } /** diff --git a/SantaBot/entry/src/main/java/org/botlibre/sdk/MainAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/MainAbility.java index e12f873..24a7ce0 100644 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/MainAbility.java +++ b/SantaBot/entry/src/main/java/org/botlibre/sdk/MainAbility.java @@ -332,7 +332,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag null, false); mCommonDialog.setContentCustomComponent(layout) .setAlignment(LayoutAlignment.CENTER) - .setSize(displayAttributes.width - 100, DirectionalLayout.LayoutConfig.MATCH_CONTENT) + .setSize(displayAttributes.width - 100, DirectionalLayout.LayoutConfig.MATCH_PARENT) .setAutoClosable(false) .setTransparent(false) .show(); @@ -1135,7 +1135,8 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag } config.id = launchInstanceId; config.name = launchInstanceName; - + WebMediumConfig finalConfig = config; + MainAbility.error(getString(ResourceTable.String_exception), new Exception(), MainAbility.this); } private static String selectInfo = ""; diff --git a/SantaBot/entry/src/main/resources/base/element/string.json b/SantaBot/entry/src/main/resources/base/element/string.json index f1134d3..7e43e4c 100644 --- a/SantaBot/entry/src/main/resources/base/element/string.json +++ b/SantaBot/entry/src/main/resources/base/element/string.json @@ -13,8 +13,8 @@ "value": "HelloWorld" }, { - "name": "exception", - "value": "403 : \n\n\n\n \n\n\nAttention Required! | Cloudflare\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n \n\n\n\n\n

\n
Please enable cookies.
\n
\n
\n \n

One more step

\n

Please complete the security check to access www.botlibre.com

\n \n
\n \n
\n
\n
\n
\n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n

Please stand by, while we are checking your browser...

\n

Redirecting...

\n
\n \n \n \n \n \n \n \n \n
\n
\n \n \n \n\n\n
\n
\n\n
\n
\n \n \n \n
\n
\n
\n
\n
\n\n
\n
\n
\n

Why do I have to complete a CAPTCHA?

\n \n

Completing the CAPTCHA proves you are a human and gives you temporary access to the web property.

\n
\n\n
\n

What can I do to prevent this in the future?

\n \n\n

If you are on a personal connection, like at home, you can run an anti-virus scan on your device to make sure it is not infected with malware.

\n\n

If you are at an office or shared network, you can ask the network administrator to run a scan across the network looking for misconfigured or infected devices.

\n \n \n \n
\n
\n
\n \n\n \n\n\n
\n
\n\n \n\n\n\n\n" + "name": "exception", + "value": "403 : \n\n\n\n \n\n\nAttention Required! | Cloudflare\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n \n\n\n\n\n
\n
Please enable cookies.
\n
\n
\n \n

One more step

\n

Please complete the security check to access www.botlibre.com

\n \n
\n \n
\n
\n
\n
\n \n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n

Please stand by, while we are checking your browser...

\n

Redirecting...

\n
\n \n \n \n \n \n \n \n \n
\n
\n \n \n \n\n\n
\n
\n\n
\n
\n \n \n \n
\n
\n
\n
\n
\n\n
\n
\n
\n

Why do I have to complete a CAPTCHA?

\n \n

Completing the CAPTCHA proves you are a human and gives you temporary access to the web property.

\n
\n\n
\n

What can I do to prevent this in the future?

\n \n\n

If you are on a personal connection, like at home, you can run an anti-virus scan on your device to make sure it is not infected with malware.

\n\n

If you are at an office or shared network, you can ask the network administrator to run a scan across the network looking for misconfigured or infected devices.

\n \n \n \n
\n
\n
\n \n\n \n\n\n
\n
\n\n \n\n\n\n\n" } ] } \ No newline at end of file -- Gitee From 4e2dded1a1a55be7d5d0cb3fc3a4d8683f5003e4 Mon Sep 17 00:00:00 2001 From: 258767-shengyu <1qaz2wsx> Date: Wed, 28 Jul 2021 14:05:59 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java index 8e93850..093fb64 100644 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java +++ b/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java @@ -1008,7 +1008,7 @@ public class MainAbility extends LibreAbility implements SelectListener, Languag null, false); mCommonDialog.setContentCustomComponent(layout) .setAlignment(LayoutAlignment.CENTER) - .setSize(displayAttributes.width - 100, DirectionalLayout.LayoutConfig.MATCH_CONTENT) + .setSize(displayAttributes.width - 100, DirectionalLayout.LayoutConfig.MATCH_PARENT) .setAutoClosable(false) .setTransparent(false) .show(); -- Gitee