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 1b2e369246c78a388e4bb12014769417654545b7..83e57f15420abd392af3f53c95d26158680e8e41 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 2735a7a92218b19c2ce9200db2d4da414b206ac4..3f13b669dc2b5bd2e1372aa14893e41a6ecd2a14 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/MainAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/MainAbility.java index da3cb81472e57eb60ff034b291700487217d7b1a..093fb64960a057577b03e4493fb1260017eacab1 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) { @@ -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(); @@ -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); } /** @@ -1776,14 +1777,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/SDKConnection.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/SDKConnection.java index 39bdafc1607ac8b71d4e06b079b955c15fc1962a..5dcd200cff74c6e136a8cbe10c994047424dc155 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 dc730b7c79062a7660747e1d0e293b48e0fca844..2bf3c593a3f8eefd783bef3e7015739ff253ea51 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 a113dbe2de311c50161407295b3e6911e3a34f63..ddeeaacb9aeccdbaf47255348967fc3a06b56e1d 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/ChatAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java index e774eb9d4581652244f5fac80c0695bba544daea..fe354c79b9d0f18eb0637052b324f3f4e430b612 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/EmotionalState.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java deleted file mode 100644 index 6482acb8bedd2ecf15941cb13b60b6e39e441ea2..0000000000000000000000000000000000000000 --- 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/HelpAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java index e259b8a65be046f7cf53dd16397a0539a8c112ed..a973ac6bb294294c2e2615c89f8703074a06c6eb 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 cc2503cb58a20a10f3880a5fab22de148bdac1e0..420fc63cc63cd6362cb781517a3e61d0c36a786a 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,68 +21,91 @@ 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. */ 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; + } + + /** + * 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/ListTagAbility.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/ListTagAbility.java index 2e63481df90ce4d100c1796fc34d733d0c10213c..8d77974fc37d4023070f2d321417ab0372fad003 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 d3e6eba0c25027d0dd8c7a7bc288187912e7fd47..13c78c5a168658a4d443d1bbfa3f8150ba0ac26e 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 907d776d7b72c07bf09b3a9cf33398d71a395232..63303f612fa036643fd1861603febe0d239c23bd 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 bb7465883db391aedab4f906113c4bfb54fe96bd..e6f856a4d6e29a380afa1999ead2662efb66343a 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/HttpAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java deleted file mode 100644 index 684bfb07544698f1546c89819d18a192d0aec04f..0000000000000000000000000000000000000000 --- 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 e6b912b0cd163dcc9f54c5255035267b546bb78f..0000000000000000000000000000000000000000 --- 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 36a291a302a9e89cd7c2d4decb7133f33ec9e49d..0000000000000000000000000000000000000000 --- 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 084535d7998c8b94886f9d8b5c31cce2ad930884..0000000000000000000000000000000000000000 --- 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 2c87b7ea62677287e8f72f99f259e9ed9c4254e7..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ /dev/null @@ -1,64 +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 3a6ca3301bc51e8b5e0456a513a95d236d49479a..0000000000000000000000000000000000000000 --- 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 95ab96c5c14751b83a3c5dfe0e14d0fbcf95e340..0000000000000000000000000000000000000000 --- 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 f3e80d6bbbd59ae052f6b03e71866a796a2ea9dc..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.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.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/HttpFetchOrCreateAction.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchOrCreateAction.java deleted file mode 100644 index 60e055ff9652220789ea2f35446a833013264940..0000000000000000000000000000000000000000 --- 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 deleted file mode 100644 index 26381dcf81a52e9020890c1944b5598ec9386f13..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchWarAction.java +++ /dev/null @@ -1,36 +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 57525bdd11cf31d152a6c92bcb6d691660048e2a..0000000000000000000000000000000000000000 --- 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 79884ce2db786e71910c2f966318bb1053dfed18..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java +++ /dev/null @@ -1,50 +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 9efe353bea2f70148c3dc8e624275901db760bdb..0000000000000000000000000000000000000000 --- 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 7b9ca7d7eceb7809ce98f7965f2b5fdaa9b9f88f..0000000000000000000000000000000000000000 --- 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 c19fac43f39271c9d2bff736e6f170c20cc34f26..0000000000000000000000000000000000000000 --- 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 a8a52bbbcb7e571e5e5ebfec2a9e8e7601864dec..0000000000000000000000000000000000000000 --- 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 c952ff726924dc5f57256ec3ce15ad7bdf78fcaa..0000000000000000000000000000000000000000 --- a/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ /dev/null @@ -1,77 +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) { -// 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()); - } - } -} \ 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 89f91d097cfe268c52dd02ebb1ea335763a9c482..2e498d316a219c2fa1e0d2b3338fcbdeb01180b7 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/dialog/LanguageDialogBuilder.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/dialog/LanguageDialogBuilder.java index aa6536400085548006667bf4a091e5452fa05e63..dcd20ae8a65134a6919b409465d3d9d78555ce56 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 a41f96049a9547e124321c52fbb57a487472e332..c1264836a4da82de04d75a929b1412df683cfc51 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 90e2d5d6536cc6427aaa9fbcd8876c4cec679f2b..3cef01c76fdbf93b15502ceb31b3aa7beba0018c 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/listener/LanguageListener.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/ability/listener/LanguageListener.java index 3523cf20581e7e5363540572e970d9c6d79fe278..a77ff1c56ffaefc797207b5f05857a95a89f9268 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 60077f9e5814e5ac0274ab168b026d2a972c7e6a..75e5450c8c1f6f361fb6ddc9352b02ac1976605a 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 7d0c9ee38abd0e72dae4d758dbfb3b6108be35eb..f6a3c42917e1e5e5644799d0156b552d320f7a18 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 deleted file mode 100644 index 11be68b73ff1b71ce94664e4f9aef3144c07623f..0000000000000000000000000000000000000000 --- 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 a0caaf3abc0383306b86a5f45b8954151a5e4a68..7369b7156aa9469fb890dd0acce10a82d4eab0df 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; @@ -120,7 +118,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 6ee4b1e8e5b09020b632529ee2fda76bdfaaba29..53158b9c9054197ea1ea21458a4af63f3b900718 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 e947ee2599b4c2b3956c1a891aa3b24495c7071e..0000000000000000000000000000000000000000 --- 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 5e672e145205c173e85ceb8cdcc40f2ba787bce4..0000000000000000000000000000000000000000 --- 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 e108292f5baab85d59242595efd0896d986a6269..d0c83b186f9215b04054c220bd0e4a3029ca255a 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 0fceac11241518e7672ed17e76b5f3cd77020d96..a729c101b51160c6f28c37d7185e1912e7b57786 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 c2ce860e88d76ffa6703b7e8afc4f92353c658a7..fec45181b7efa2d8da0014ed0252988b6947d9c4 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 9e93cab036e696e4a186a3012d6cc8287050f338..d47f7e68c6555ffaa20fb1fb7ca0ed9f82b7bdbf 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 f2984ab85e4cd625ee0104693144485033f42e9e..208cd8417f7697c41448c430c6e6012e760a762d 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 205cead4f67dd8a35766e1bc4e3a042a5091a641..0000000000000000000000000000000000000000 --- 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 b61bbca4a522a5dd0fb5ba96e6c2eeaf90fec807..0000000000000000000000000000000000000000 --- 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 6eee6eed5445f407f328ff8e584e18e53b2afb27..46d4cb6476301b876225d1ac225afc300c63914e 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 679f144a115210cd3db3fff03c215d5faeca4359..aab18b422addc7914e5fcd7a5cb9c8fbcef8dbe3 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 e8133daa45b816ee85ca962bbdbf03dd1fec28b6..70ba7260b8390a597aec8b97e5b4105b92de6fde 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 6fedbf008729b343fa23501d1886d7a85173fd84..1d5d9b7a59ddb219989107be3e7e8ce1e6e8f6a7 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 9c99d0f4587573b10e584409fd501745b5e23942..0000000000000000000000000000000000000000 --- 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 59e8f8070122c5fa3eb144210d6f4d0b72c56aee..78207842bbf9a4dd36fffecd376b8bc7c5965fde 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 014f21dd000859d3ba1e03707161a5e73b821d6e..33fd536c6239de7a0de05a73ae57fc8431ea192a 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 451d66cbc3d6acaa67583904110d72cbf4891c33..0000000000000000000000000000000000000000 --- 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 772b30a606fd0f3d0b2c907ee9651eb24d36f1bb..cc4c7b131017727546ed86f1d20a0d58d51cbe25 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 cb8e98b56611e49058e5e42b5222ce3595fcb00e..0000000000000000000000000000000000000000 --- 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 8984f85b52fd7f88b6925d64c5ef54cb72e1d8b6..0449961edf618a4569d1427879290c9e235ec41b 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 bf74806b009d1bb46c59b47e6fda23172871cfaf..36022bc6d7137dba774f4e7f6af8f119054c7b94 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 c8bddf646c14aa7ed19b0e558f74052120d65f55..0000000000000000000000000000000000000000 --- 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 a536caff8a076302ba5a3ff2c631d8e824b0de7d..d7b0c0ce96bc5ba286f6735bebab631b491fe566 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 b90dfe5cde4afc7f11d588e3488c7724da8e7c4a..8ff3cdc2e7bc4725fc536c5f12de656b007c7f3a 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 63a6d47912a775026950ecd069c8fb84693d76fa..0000000000000000000000000000000000000000 --- 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 0bb5194f6f542a41bc94777c431b4e0a1a2e4473..0000000000000000000000000000000000000000 --- 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 b68c5108ca66320c3dea51d07a72326f7e2b4100..0000000000000000000000000000000000000000 --- 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 d7261184b8cc0050998991947f00b838590854d8..50dcc8d3ef6f5e911a0f27ebd40e38eea2bbcbd7 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 61e47a61d2a1869a7269821388d5a8ecd17b4ce2..0000000000000000000000000000000000000000 --- 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 2c9a81fb6ebc7f34360880283ff0b36ea0719e81..78b63ce6b69c4f85a6731e7094c9af1810717aba 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 5fe39205c5f55b891520bd7a604d7910bd4aa424..1807c1cf60759d711fb247e6956b34d9f509282a 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/AsyncTask.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java deleted file mode 100644 index 3b8c833de7505109ff107a2ce5f7a4461152bb2a..0000000000000000000000000000000000000000 --- 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 81de12c691050ac5684711f47d4eb0d9a22af8f3..d3b7d69cd93f81a3a7b93e521feb29dc82d1eec5 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/TextStream.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/TextStream.java index 7cce43a70f306e2d170b135e604b9ae375aa447f..990b3bfa381a30e17be6ebd63aad748bc698a1b2 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/ToastUtils.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java index 0117f4c3237a27e6a541861171edd635a40594a4..dc514a4adfde8c6c0fd5b41916a4a0075ad4f359 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/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java b/BotLibre/entry/src/main/java/org/botlibre/sdk/util/Utils.java index c0d79872c48cd4ac42670e2fc01b7b939f03e691..350a746631deb14c196cf03fc11b25fee09a0c6f 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 1b2e369246c78a388e4bb12014769417654545b7..83e57f15420abd392af3f53c95d26158680e8e41 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/MyApplication.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/MyApplication.java index ed615153f007f89e717302d41c28fc1a336a62ff..7ddc6afc408730815220d8f09064d297c4dab296 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/SDKException.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java index dc730b7c79062a7660747e1d0e293b48e0fca844..2bf3c593a3f8eefd783bef3e7015739ff253ea51 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 a113dbe2de311c50161407295b3e6911e3a34f63..62ca2ab1a14ba186644e653e5e3be0bb55bcf0a9 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 6482acb8bedd2ecf15941cb13b60b6e39e441ea2..20d94d8ae8f1de6cd913da5aaee5499e292c4db4 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/HelpAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java index b52e03f4a478deba0cf5ded3ad9171352b93b077..dbfd867042337345f0864f113d5842a0a9c404ff 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 772f19f30b127edc6d52ddded8306a817a90ab11..3a14f5049861832adea59836c5a80c2def80ef88 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 5665b7765f560882507d48fa2fab39bed1da95e0..40d7369b8aab01280ffa370513d7d8f4248f47f0 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/LoginAbility.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index 24ff09cab077a0aae4e07087baf3860e46e49c14..187591643093d6ca41c99e428cb8104223ba1802 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 be08f49582c67657ca185c05bb86b4b77ac0230b..1e1a08d1bc92e9966a61d6686be7455643b1df7f 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 41d7ff83562f53454d1c37353570731af6095bef..90e7bd0617baf55ae2688934d56258051db81e78 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/HttpAction.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java deleted file mode 100644 index 95df90edcd50d50617672c9332fb18560d6cd484..0000000000000000000000000000000000000000 --- 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 780d55257d687d948ae2becdaed4ac6562a400fc..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.java +++ /dev/null @@ -1,64 +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 8016ed70a3ce6a3c6925c14525ba64f259be3ec2..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchAction.java +++ /dev/null @@ -1,135 +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(); - } - -// @Override -// protected String doInBackground(Void... params) { -// try { -// -// } catch (Exception exception) { -// this.exception = exception; -// } -// return ""; -// } - -// public void superOnPostExecute(String xml) { -// super.onPostExecute(xml); -// } - - @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) { -// 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()); - - 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 dc18ddc5c3156581afc80e66a37b087e0bec9654..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFlagUserAction.java +++ /dev/null @@ -1,52 +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; - } - //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 deleted file mode 100644 index 42ea5ac37af0d014cfefd4cbbddb3ab109cc42a6..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpGetAvatarMediaAction.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.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(); - } -// startOpenAbility(this.ability, AvatarEditorAbility.class.getName()); - } -} \ 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 8866e8ea92b971e0b8922065e8f0b0af7608f700..0000000000000000000000000000000000000000 --- 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 584fc19cfc2c5b2d4c8c4580482c23abc89fe223..0000000000000000000000000000000000000000 --- 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 b6be9cf7f7783155eaa4ea845a1a0bcd6997f265..0000000000000000000000000000000000000000 --- 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 17f5e179af1eadb767b8d39cd6c0bd56e9cbe571..0000000000000000000000000000000000000000 --- 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 a8a52bbbcb7e571e5e5ebfec2a9e8e7601864dec..0000000000000000000000000000000000000000 --- 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 c952ff726924dc5f57256ec3ce15ad7bdf78fcaa..0000000000000000000000000000000000000000 --- a/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ /dev/null @@ -1,77 +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) { -// 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()); - } - } -} \ 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 89f91d097cfe268c52dd02ebb1ea335763a9c482..2e498d316a219c2fa1e0d2b3338fcbdeb01180b7 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 7d0c9ee38abd0e72dae4d758dbfb3b6108be35eb..f6a3c42917e1e5e5644799d0156b552d320f7a18 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 deleted file mode 100644 index 7be2f536b9e4ca8d02ba737f6582b928029accf4..0000000000000000000000000000000000000000 --- 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 5864f9a11be7455c60a0675f1d52bff37ccc9e7c..992d34e5a92fe5c31836d0259b933e3379f1510e 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; @@ -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(); @@ -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); } @@ -213,7 +225,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi * getBot1 * * @return InstanceConfig - * */ + */ public static InstanceConfig getBot1() { return bot1; } @@ -222,7 +234,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi * setBot1 * * @param bot1 InstanceConfig - * */ + */ public static void setBot1(InstanceConfig bot1) { StartWarAbility.bot1 = bot1; } @@ -231,7 +243,7 @@ public class StartWarAbility extends LibreAbility implements Component.ClickedLi * getBot2 * * @return InstanceConfig - * */ + */ public static InstanceConfig getBot2() { return bot2; } @@ -240,7 +252,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 8a1ac5e7523e6790480e21c42b3929e36fc9b0f8..411f57b9941e4bd5bd28cdf86aa3c806a639d05d 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 0078f540f6c6ab788ccc638bc9a92f519a49cadf..04f45d42c724f4da3f02903d8994aca344a0f5de 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 5e672e145205c173e85ceb8cdcc40f2ba787bce4..64ff99b7afbdb1f5beda52013c24f3de37feb52a 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 00b27ad42dc4233b1138230a5933b9b6e3916a6c..6479e186ab8a6f21cdac85cc1c561badd9c72080 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 becc5bc78955d2f086c902d4afcaefdfa1ac7cff..37143288dbbbff1b26a3750873e3b685a6568e17 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 c2ce860e88d76ffa6703b7e8afc4f92353c658a7..fec45181b7efa2d8da0014ed0252988b6947d9c4 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 9e93cab036e696e4a186a3012d6cc8287050f338..d47f7e68c6555ffaa20fb1fb7ca0ed9f82b7bdbf 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 dac4c7bc152a23c4ca4d920a6899d8ceb409fa35..331cee470c0787250a91a3ce50af7dc26ad7ac89 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 c9379f874672b09ed9a64d56cc734108f56e6f08..d8310d1053cbe68bda40fc0383bab95d627eca72 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 b90cf07899883181f1126813a37fa9f75991360a..07175e8b93a48cd9413bbcf098adc4c26dab96bc 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 6eee6eed5445f407f328ff8e584e18e53b2afb27..46d4cb6476301b876225d1ac225afc300c63914e 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 679f144a115210cd3db3fff03c215d5faeca4359..aab18b422addc7914e5fcd7a5cb9c8fbcef8dbe3 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 4578bfc2a0a0bc6ba0ace871fd198a4e25ecfa36..c09c4265cb53dd5896121ff61ae275d133d46b2a 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 6fedbf008729b343fa23501d1886d7a85173fd84..1d5d9b7a59ddb219989107be3e7e8ce1e6e8f6a7 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 9c99d0f4587573b10e584409fd501745b5e23942..329707a18808bba039b8d112cd3f62af1cd30ae7 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 59e8f8070122c5fa3eb144210d6f4d0b72c56aee..78207842bbf9a4dd36fffecd376b8bc7c5965fde 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 014f21dd000859d3ba1e03707161a5e73b821d6e..33fd536c6239de7a0de05a73ae57fc8431ea192a 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 451d66cbc3d6acaa67583904110d72cbf4891c33..19d09592a84e17b14f49944ae0ff70fcc7083d0d 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 772b30a606fd0f3d0b2c907ee9651eb24d36f1bb..cc4c7b131017727546ed86f1d20a0d58d51cbe25 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 d6bc1899f7df8a1a0988d9171d0098a92397c106..ccb60599b1ce6ed8d41f58cdaa729b78d6eaa268 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 8984f85b52fd7f88b6925d64c5ef54cb72e1d8b6..0449961edf618a4569d1427879290c9e235ec41b 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 bf74806b009d1bb46c59b47e6fda23172871cfaf..36022bc6d7137dba774f4e7f6af8f119054c7b94 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 c8bddf646c14aa7ed19b0e558f74052120d65f55..64b83bf1ca53a4d2c7a5224f5af28e1241452ec1 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 a536caff8a076302ba5a3ff2c631d8e824b0de7d..d7b0c0ce96bc5ba286f6735bebab631b491fe566 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 b90dfe5cde4afc7f11d588e3488c7724da8e7c4a..8ff3cdc2e7bc4725fc536c5f12de656b007c7f3a 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 63a6d47912a775026950ecd069c8fb84693d76fa..9694370abb00a95cf6a3dc48d254cf9131052a3d 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 0bb5194f6f542a41bc94777c431b4e0a1a2e4473..cd80f18823b84cca9851e922b472d5315d3d6144 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 b68c5108ca66320c3dea51d07a72326f7e2b4100..5961d5f80c9782f4b9e225577fd83d9c5b030d33 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 21deb25795bb58bc6fa1c7ee40b1e5b2d79ade7c..c258f20fa4c22c43c66fa5575d594b1535d43ce6 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 61e47a61d2a1869a7269821388d5a8ecd17b4ce2..9ba0857b43e99ca7933a09a6c6c6e7063b94e911 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 2c9a81fb6ebc7f34360880283ff0b36ea0719e81..78b63ce6b69c4f85a6731e7094c9af1810717aba 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 5fe39205c5f55b891520bd7a604d7910bd4aa424..1807c1cf60759d711fb247e6956b34d9f509282a 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/ApplicationJumpUtil.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ApplicationJumpUtil.java index 2307ffbd3d4959a4e76d709ae57e56dbae753e22..fae7a8fcd3e6f39ed28863a56121f24b85e91b18 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 3b8c833de7505109ff107a2ce5f7a4461152bb2a..0000000000000000000000000000000000000000 --- 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/TextStream.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/TextStream.java index 92228166ddfbf1d6f1ebb33e2a6d24d20646572f..f342afd129e1a271121657d72bd03d0895a40552 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/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java b/BotLibreOffline/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java index 0117f4c3237a27e6a541861171edd635a40594a4..dc514a4adfde8c6c0fd5b41916a4a0075ad4f359 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 744d2f4bfa33b185c409a403a5f83f9a16da2fe6..0000000000000000000000000000000000000000 --- 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/SDKException.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/SDKException.java index e60124543808dae822388a6c9bf101b759f6431b..7290f41570b6f3cbe7e6d7ed4b4469efd6d84a6d 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/CreateUserAbility.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/CreateUserAbility.java index 16c4bbae7f9d80bce10f9a2b71f09cf1128a7f52..4686a412ee3616b17d507024a45d69697f5ac595 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 4bea3153e018847c59cc3a3b4de95e8142f84434..9753d187e3f1f5a07c88ea45e2786b2809490a0d 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 29003b22ca5de0a400b2bd7bb0154162343e5454..07d514d36ffe6cbc5242d26e3427e72af2722981 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,55 +19,73 @@ 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. */ 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); + } - 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); + /** + * 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; - HttpConnectAction action = new HttpConnectAction(this, config, true); - action.execute(); + + UserConfig config = new UserConfig(); + config.user = user; + config.password = password; + 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() { - 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/ability/actions/HttpAction.java b/PizzaBotOffline/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpAction.java deleted file mode 100644 index f3eab37267580bbf3a017a26a3fed6c22d37d510..0000000000000000000000000000000000000000 --- 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 e0147b7b259370ce2a80e65ba2058ca3b797eab0..0000000000000000000000000000000000000000 --- 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 8322d344b317f88901ab3604f1b83cf2a175309b..0000000000000000000000000000000000000000 --- 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 d9c4cbfaeed93ae9aa55e2f82c6d8eac7f80c2ca..0000000000000000000000000000000000000000 --- 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 5d84dc9af8cf75ce6eed16a962a90647c711461c..33d29287ccd4d9e6cb33b74d20e086f4b42cbe9e 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,571 +29,392 @@ 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; + public String background; + public String icon; -// 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; - return config; - } - - public String toXML() { - StringWriter writer = new StringWriter(); - writer.write(""); - return writer.toString(); - } - - - public void parseXML(Element element) { - super.parseXML(element); - } + public String getType() { + return "avatar"; + } - /** - * 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 AvatarConfig() { + mediaConfig = new HashMap(); + } - /** - * 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; - } + public WebMediumConfig credentials() { + AvatarConfig config = new AvatarConfig(); + config.id = this.id; + return config; + } - 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 toXML() { + StringWriter writer = new StringWriter(); + writer.write(""); + return writer.toString(); + } - public String getBackground(){ - return background; - } - public String getIcon(){ - return icon; - } + 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(); + + 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 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 b63e9e5abbdf8280d6cfd59686d96bfccede7065..abb935a2a713dae25204f61db4b614a53234a564 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 b77fbfc5d1fe37719e6459b7f64287311d19a247..67ee97b48b1331b5b51726d587c5b0d4426a3992 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 48c4e824779bcd05a1ded485c3126a5af57368e7..2144ffbe6b18f9824b8236334146a9aa690691b3 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 ec5815019399e1fc43e01773763e708d7258dfba..ef3a17f8543afc69db113bd5758198e47b01c852 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 294a6179bbac3479da1bfc9cc603b8a64d0a8948..21e553de5ef9bc7a864cb6b9043b4bcdef92570e 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,89 +15,90 @@ 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. */ -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 boolean isVideo() { + return this.avatarType != null && this.avatarType.indexOf("video") != -1; + } + + 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"); - 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(); + } + } - 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 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 0d761c6ac5a3cf7dbb75b855990ee11dd0e014a6..99478fe88608dc1f565b394c69b6950bc747bb71 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 72ab06a91b4df75bce1c7e2524eb9d9c3f4a7338..b35125fdb3f6d28ec260fe00b1879d2b6c14328d 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 de1f166acacddbfb72e3cbffff6dcce14d80cc37..04ddbaedca9d8c241a543b29f99fe8e49be6fffd 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 a7249926880420a7b8e127230251b601dd1581f2..05d43adc3eda2de352867542928ffef24d661136 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 8342f281b2a63360c77352a7997a6db473f1af0c..8e0bb10fad80b48c2a78e9be5aed1bdeb6e1f36c 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 9490aca5de334d5319b93aca33afcc8df3aa8951..aead02f80f4cedb20041bf0aa02c5e52b04aae38 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 36aa7895fa60026071e682326b694789a9188fcd..4f16f33161434d632735a22081bb5e415da9cc02 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 dda7ac31e77db10537e27233c7c9306d47037944..1b9296740d8ce2cccec438b45502af2672ada97c 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,188 +15,188 @@ 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; /** * 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); + } + + @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 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 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(""); + } - @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 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")); + } - public String toXML() { - StringWriter writer = new StringWriter(); - writeXML(writer); - return writer.toString(); - } + 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 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; - } + 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 36e43c057a1478594beed82fd7376652dcb5ff61..a316f90457fa4c95f2b20523b08755adcc6d3c2d 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 d44891cdf2c5186b61186349078ef634d9d6dc31..68d9b5165afbbe86838e0273e7b64cfcec16ed08 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,67 @@ 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(); + } + } } 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 d14869d82c01797656906c4f6ff396a495bebed1..f4a2d723e95d248bdcb827370cdf86fbf9365a03 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 01ee7fa8a04a266c3b3ef0591b8fcd1316a1c4d8..29fba15e16258871b6204e98670cad1d77f6779d 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 8de5fe4bb9bd10c0e75167699a9d9a750de0608b..561ed21bee4437f53b03bca774f5c2479de4779f 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/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 3b8c833de7505109ff107a2ce5f7a4461152bb2a..0000000000000000000000000000000000000000 --- 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/BOTlibreCredentials.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/BOTlibreCredentials.java index 1b2e369246c78a388e4bb12014769417654545b7..83e57f15420abd392af3f53c95d26158680e8e41 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 ace1a72b4ccef374c8aaac21649152bd2d1ea082..9aa2e1892bbdd16a3b7543e7d2ff4cc592016884 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/MainAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/MainAbility.java index e12f87328d245af0c9450e76b70fa2932a3244bf..24a7ce0df8982c57eeef294da4186cb873bc5ab0 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/java/org/botlibre/sdk/SDKException.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/SDKException.java index dc730b7c79062a7660747e1d0e293b48e0fca844..2bf3c593a3f8eefd783bef3e7015739ff253ea51 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 a113dbe2de311c50161407295b3e6911e3a34f63..ddeeaacb9aeccdbaf47255348967fc3a06b56e1d 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/ChatAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ChatAbility.java index 94cebc965c4732370033536e3fd4fef7c8d0016f..742bbf07cd10dbd65482edd28d0def01e6e2bcf3 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/EmotionalState.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/EmotionalState.java deleted file mode 100644 index 6482acb8bedd2ecf15941cb13b60b6e39e441ea2..0000000000000000000000000000000000000000 --- 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/HelpAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/HelpAbility.java index a986d14316465337a2f6758bd9db408c18edcba1..9da37952e5495b1e7661a96e8b525d8bc91f9f67 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 a4d18ed9178325989766545dd93b1a0e6446741d..e811c00a4d6ed3d6b9b5e137f344a8208a4a9519 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,25 +21,48 @@ 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. */ 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); + } + + /** + * 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/ListTemplateView.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/ListTemplateView.java index 543cd67f5f8863eebe9cc0b5b1a542c4f851979f..10f02dc5adb4d47e5e57a095815dbbf795bd7ea1 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/LoginAbility.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/LoginAbility.java index 9b024b9e2b3fb618e35e5a5b2c4ba80b953576e4..0af935574f4b3c049272831b2090b1918d57d921 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 8b7fb90b38309bb97988a579a42a23f928c5e5a7..0000000000000000000000000000000000000000 --- 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 220cb17d098bfe72d922bdaa8517a82ebb255123..0000000000000000000000000000000000000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpChatAction.java +++ /dev/null @@ -1,162 +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 36a291a302a9e89cd7c2d4decb7133f33ec9e49d..0000000000000000000000000000000000000000 --- 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 55b090234499df4524b0de1de372e82e89095549..0000000000000000000000000000000000000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpCreateUserAction.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 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 f3e80d6bbbd59ae052f6b03e71866a796a2ea9dc..0000000000000000000000000000000000000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpFetchChatAvatarAction.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.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 65e368d2aec6272b4a420d3153675afc48e35cd4..0000000000000000000000000000000000000000 --- 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 816ff61a8b7569a6e5d84b49e497debac02891d8..0000000000000000000000000000000000000000 --- 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 b3b4d6e1871dabfef0f22c68bfa4fe245aa70cb1..0000000000000000000000000000000000000000 --- 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 a8a52bbbcb7e571e5e5ebfec2a9e8e7601864dec..0000000000000000000000000000000000000000 --- 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 c952ff726924dc5f57256ec3ce15ad7bdf78fcaa..0000000000000000000000000000000000000000 --- a/SantaBot/entry/src/main/java/org/botlibre/sdk/ability/actions/HttpUIResultAction.java +++ /dev/null @@ -1,77 +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) { -// 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()); - } - } -} \ 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 89f91d097cfe268c52dd02ebb1ea335763a9c482..2e498d316a219c2fa1e0d2b3338fcbdeb01180b7 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 8e66c9b7c1b68df7c1d5b4eb98bbbc80e35f2e86..f7f9615012938c3963206f6083bcacb26a249c78 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 12704d21752ed72cd0325f2b27b718487896f1ce..c97572a878ec14d977fa0bd98ac1d980f8f93279 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 7d0c9ee38abd0e72dae4d758dbfb3b6108be35eb..f6a3c42917e1e5e5644799d0156b552d320f7a18 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 deleted file mode 100644 index 11be68b73ff1b71ce94664e4f9aef3144c07623f..0000000000000000000000000000000000000000 --- 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 a41ecb34401be012b0717c40ebd5b832e8944616..8906d0840a372abaa3491c3fd4b7108448c9460c 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/config/AvatarConfig.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/config/AvatarConfig.java index 41dbaed5e671dd26bfe9b681ea0cfb8c343547ce..fd38b28821e0b665f81fd78a7e4648c73e8431d3 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 58cab3253a8b0588fe1aa9c30d2c7d3988e5b620..a480e484e1f06acaa9a45d9499adf3384793e958 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 e947ee2599b4c2b3956c1a891aa3b24495c7071e..81a733440dc2dc75c48ee81ed0afbd9afe8e41e9 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 5e672e145205c173e85ceb8cdcc40f2ba787bce4..64ff99b7afbdb1f5beda52013c24f3de37feb52a 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 480720cf9f9019f0ac911425d07d013069068f60..867d9d785225c2f95d9e78a79b1772d9fb9a8e81 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 ba57ec1fceab500c8d2fc44a285066a91d9d02fc..98126b9fca361e000f2fe6311b367f52e62bf6bb 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 c2ce860e88d76ffa6703b7e8afc4f92353c658a7..fec45181b7efa2d8da0014ed0252988b6947d9c4 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 9e93cab036e696e4a186a3012d6cc8287050f338..d47f7e68c6555ffaa20fb1fb7ca0ed9f82b7bdbf 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 dac4c7bc152a23c4ca4d920a6899d8ceb409fa35..331cee470c0787250a91a3ce50af7dc26ad7ac89 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 21c1a492c071bd9a8f8137e30cc9020af902cfe0..349ef72c4c02be31c00a15df088c14b216a50546 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 893cd6f4b7ca5911fee6c7d964d7fbbed1f1158b..9f854f9df4eb990a1c7ad7b979ce6763d125e345 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 6eee6eed5445f407f328ff8e584e18e53b2afb27..46d4cb6476301b876225d1ac225afc300c63914e 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 679f144a115210cd3db3fff03c215d5faeca4359..aab18b422addc7914e5fcd7a5cb9c8fbcef8dbe3 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 e8133daa45b816ee85ca962bbdbf03dd1fec28b6..70ba7260b8390a597aec8b97e5b4105b92de6fde 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 6fedbf008729b343fa23501d1886d7a85173fd84..1d5d9b7a59ddb219989107be3e7e8ce1e6e8f6a7 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 9c99d0f4587573b10e584409fd501745b5e23942..329707a18808bba039b8d112cd3f62af1cd30ae7 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 59e8f8070122c5fa3eb144210d6f4d0b72c56aee..78207842bbf9a4dd36fffecd376b8bc7c5965fde 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 014f21dd000859d3ba1e03707161a5e73b821d6e..33fd536c6239de7a0de05a73ae57fc8431ea192a 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 451d66cbc3d6acaa67583904110d72cbf4891c33..19d09592a84e17b14f49944ae0ff70fcc7083d0d 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 772b30a606fd0f3d0b2c907ee9651eb24d36f1bb..cc4c7b131017727546ed86f1d20a0d58d51cbe25 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 3f74f813a34cbdca218750e4a8b47b6518aed4df..fa8d0df67e618222413931574bea7854333e038f 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 8984f85b52fd7f88b6925d64c5ef54cb72e1d8b6..0449961edf618a4569d1427879290c9e235ec41b 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 bf74806b009d1bb46c59b47e6fda23172871cfaf..36022bc6d7137dba774f4e7f6af8f119054c7b94 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 c8bddf646c14aa7ed19b0e558f74052120d65f55..64b83bf1ca53a4d2c7a5224f5af28e1241452ec1 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 a536caff8a076302ba5a3ff2c631d8e824b0de7d..d7b0c0ce96bc5ba286f6735bebab631b491fe566 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 b90dfe5cde4afc7f11d588e3488c7724da8e7c4a..8ff3cdc2e7bc4725fc536c5f12de656b007c7f3a 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 63a6d47912a775026950ecd069c8fb84693d76fa..9694370abb00a95cf6a3dc48d254cf9131052a3d 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 0bb5194f6f542a41bc94777c431b4e0a1a2e4473..cd80f18823b84cca9851e922b472d5315d3d6144 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 b68c5108ca66320c3dea51d07a72326f7e2b4100..5961d5f80c9782f4b9e225577fd83d9c5b030d33 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 426ea2ac97afe9eef2269db13da4181b9082022a..cfe5504c10adb3a0544ca6f14e1ee3d69afb75a0 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 61e47a61d2a1869a7269821388d5a8ecd17b4ce2..9ba0857b43e99ca7933a09a6c6c6e7063b94e911 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 2c9a81fb6ebc7f34360880283ff0b36ea0719e81..78b63ce6b69c4f85a6731e7094c9af1810717aba 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 5fe39205c5f55b891520bd7a604d7910bd4aa424..1807c1cf60759d711fb247e6956b34d9f509282a 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/AsyncTask.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/AsyncTask.java index 3b8c833de7505109ff107a2ce5f7a4461152bb2a..8ecbc330921c2494f87f74c9d18b2b3eb6c438b0 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/TextStream.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/TextStream.java index d0382e63fa3acde4e4c4fd63757c168a1f2bf0e8..138290d4fedb509b39c041f4d5fe74b6f96b8480 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/ToastUtils.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/ToastUtils.java index 0117f4c3237a27e6a541861171edd635a40594a4..dc514a4adfde8c6c0fd5b41916a4a0075ad4f359 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/main/java/org/botlibre/sdk/util/Utils.java b/SantaBot/entry/src/main/java/org/botlibre/sdk/util/Utils.java index c5aecf8deba63d3f68bbc939b14e364b82c7dbee..a73489539c7dffc28192b71bec9bb2b5ac3a5a78 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 diff --git a/SantaBot/entry/src/main/resources/base/element/string.json b/SantaBot/entry/src/main/resources/base/element/string.json index f1134d3b2a1ac34ec04a034a89ab4c1d427797b6..7e43e4ce3d11158cafcb8a7a222857befcf058b3 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 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 98b1db58635b535fdf92233104febc98f299bffa..0000000000000000000000000000000000000000 --- 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