List of usage examples for org.apache.http.util TextUtils isEmpty
public static boolean isEmpty(CharSequence charSequence)
From source file:org.asamk.signal.Main.java
public static void main(String[] args) { // Workaround for BKS truststore Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 1); Namespace ns = parseArgs(args); if (ns == null) { System.exit(1);/*from ww w.j ava 2 s .c o m*/ } final String username = ns.getString("username"); Manager m; Signal ts; DBusConnection dBusConn = null; try { if (ns.getBoolean("dbus") || ns.getBoolean("dbus_system")) { try { m = null; int busType; if (ns.getBoolean("dbus_system")) { busType = DBusConnection.SYSTEM; } else { busType = DBusConnection.SESSION; } dBusConn = DBusConnection.getConnection(busType); ts = (Signal) dBusConn.getRemoteObject(SIGNAL_BUSNAME, SIGNAL_OBJECTPATH, Signal.class); } catch (DBusException e) { e.printStackTrace(); if (dBusConn != null) { dBusConn.disconnect(); } System.exit(3); return; } } else { String settingsPath = ns.getString("config"); if (TextUtils.isEmpty(settingsPath)) { settingsPath = System.getProperty("user.home") + "/.config/signal"; if (!new File(settingsPath).exists()) { String legacySettingsPath = System.getProperty("user.home") + "/.config/textsecure"; if (new File(legacySettingsPath).exists()) { settingsPath = legacySettingsPath; } } } m = new Manager(username, settingsPath); ts = m; if (m.userExists()) { try { m.load(); } catch (Exception e) { System.err .println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage()); System.exit(2); return; } } } switch (ns.getString("command")) { case "register": if (dBusConn != null) { System.err.println("register is not yet implemented via dbus"); System.exit(1); } if (!m.userHasKeys()) { m.createNewIdentity(); } try { m.register(ns.getBoolean("voice")); } catch (IOException e) { System.err.println("Request verify error: " + e.getMessage()); System.exit(3); } break; case "verify": if (dBusConn != null) { System.err.println("verify is not yet implemented via dbus"); System.exit(1); } if (!m.userHasKeys()) { System.err.println("User has no keys, first call register."); System.exit(1); } if (m.isRegistered()) { System.err.println("User registration is already verified"); System.exit(1); } try { m.verifyAccount(ns.getString("verificationCode")); } catch (IOException e) { System.err.println("Verify error: " + e.getMessage()); System.exit(3); } break; case "link": if (dBusConn != null) { System.err.println("link is not yet implemented via dbus"); System.exit(1); } // When linking, username is null and we always have to create keys m.createNewIdentity(); String deviceName = ns.getString("name"); if (deviceName == null) { deviceName = "cli"; } try { System.out.println(m.getDeviceLinkUri()); m.finishDeviceLink(deviceName); System.out.println("Associated with: " + m.getUsername()); } catch (TimeoutException e) { System.err.println("Link request timed out, please try again."); System.exit(3); } catch (IOException e) { System.err.println("Link request error: " + e.getMessage()); System.exit(3); } catch (InvalidKeyException e) { e.printStackTrace(); System.exit(3); } catch (UserAlreadyExists e) { System.err.println("The user " + e.getUsername() + " already exists\nDelete \"" + e.getFileName() + "\" before trying again."); System.exit(3); } break; case "addDevice": if (dBusConn != null) { System.err.println("link is not yet implemented via dbus"); System.exit(1); } if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } try { m.addDeviceLink(new URI(ns.getString("uri"))); } catch (IOException e) { e.printStackTrace(); System.exit(3); } catch (InvalidKeyException e) { e.printStackTrace(); System.exit(2); } catch (URISyntaxException e) { e.printStackTrace(); System.exit(2); } break; case "listDevices": if (dBusConn != null) { System.err.println("listDevices is not yet implemented via dbus"); System.exit(1); } if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } try { List<DeviceInfo> devices = m.getLinkedDevices(); for (DeviceInfo d : devices) { System.out.println("Device " + d.getId() + (d.getId() == m.getDeviceId() ? " (this device)" : "") + ":"); System.out.println(" Name: " + d.getName()); System.out.println(" Created: " + d.getCreated()); System.out.println(" Last seen: " + d.getLastSeen()); } } catch (IOException e) { e.printStackTrace(); System.exit(3); } break; case "removeDevice": if (dBusConn != null) { System.err.println("removeDevice is not yet implemented via dbus"); System.exit(1); } if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } try { int deviceId = ns.getInt("deviceId"); m.removeLinkedDevices(deviceId); } catch (IOException e) { e.printStackTrace(); System.exit(3); } break; case "send": if (dBusConn == null && !m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } if (ns.getBoolean("endsession")) { if (ns.getList("recipient") == null) { System.err.println("No recipients given"); System.err.println("Aborting sending."); System.exit(1); } try { ts.sendEndSessionMessage(ns.<String>getList("recipient")); } catch (IOException e) { handleIOException(e); } catch (EncapsulatedExceptions e) { handleEncapsulatedExceptions(e); } catch (AssertionError e) { handleAssertionError(e); } catch (DBusExecutionException e) { handleDBusExecutionException(e); } catch (UntrustedIdentityException e) { e.printStackTrace(); } } else { String messageText = ns.getString("message"); if (messageText == null) { try { messageText = IOUtils.toString(System.in); } catch (IOException e) { System.err.println("Failed to read message from stdin: " + e.getMessage()); System.err.println("Aborting sending."); System.exit(1); } } try { List<String> attachments = ns.getList("attachment"); if (attachments == null) { attachments = new ArrayList<>(); } if (ns.getString("group") != null) { byte[] groupId = decodeGroupId(ns.getString("group")); ts.sendGroupMessage(messageText, attachments, groupId); } else { ts.sendMessage(messageText, attachments, ns.<String>getList("recipient")); } } catch (IOException e) { handleIOException(e); } catch (EncapsulatedExceptions e) { handleEncapsulatedExceptions(e); } catch (AssertionError e) { handleAssertionError(e); } catch (GroupNotFoundException e) { handleGroupNotFoundException(e); } catch (AttachmentInvalidException e) { System.err.println("Failed to add attachment: " + e.getMessage()); System.err.println("Aborting sending."); System.exit(1); } catch (DBusExecutionException e) { handleDBusExecutionException(e); } catch (UntrustedIdentityException e) { e.printStackTrace(); } } break; case "receive": if (dBusConn != null) { try { dBusConn.addSigHandler(Signal.MessageReceived.class, new DBusSigHandler<Signal.MessageReceived>() { @Override public void handle(Signal.MessageReceived s) { System.out .print(String.format("Envelope from: %s\nTimestamp: %d\nBody: %s\n", s.getSender(), s.getTimestamp(), s.getMessage())); if (s.getGroupId().length > 0) { System.out.println("Group info:"); System.out.println(" Id: " + Base64.encodeBytes(s.getGroupId())); } if (s.getAttachments().size() > 0) { System.out.println("Attachments: "); for (String attachment : s.getAttachments()) { System.out.println("- Stored plaintext in: " + attachment); } } System.out.println(); } }); } catch (DBusException e) { e.printStackTrace(); } while (true) { try { Thread.sleep(10000); } catch (InterruptedException e) { System.exit(0); } } } if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } int timeout = 60; if (ns.getInt("timeout") != null) { timeout = ns.getInt("timeout"); } boolean returnOnTimeout = true; if (timeout < 0) { returnOnTimeout = false; timeout = 3600; } try { for (int i = 0; i < 10; i++) { System.out.println("Numero di threads: " + Thread.activeCount()); m.receiveMessages(timeout, returnOnTimeout, new ReceiveMessageHandler(m)); } } catch (IOException e) { System.err.println("Error while receiving messages: " + e.getMessage()); System.exit(3); } catch (AssertionError e) { handleAssertionError(e); } break; case "quitGroup": if (dBusConn != null) { System.err.println("quitGroup is not yet implemented via dbus"); System.exit(1); } if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } try { m.sendQuitGroupMessage(decodeGroupId(ns.getString("group"))); } catch (IOException e) { handleIOException(e); } catch (EncapsulatedExceptions e) { handleEncapsulatedExceptions(e); } catch (AssertionError e) { handleAssertionError(e); } catch (GroupNotFoundException e) { handleGroupNotFoundException(e); } catch (UntrustedIdentityException e) { e.printStackTrace(); } break; case "updateGroup": if (dBusConn != null) { System.err.println("updateGroup is not yet implemented via dbus"); System.exit(1); } if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } try { byte[] groupId = null; if (ns.getString("group") != null) { groupId = decodeGroupId(ns.getString("group")); } byte[] newGroupId = m.sendUpdateGroupMessage(groupId, ns.getString("name"), ns.<String>getList("member"), ns.getString("avatar")); if (groupId == null) { System.out.println("Creating new group \"" + Base64.encodeBytes(newGroupId) + "\" "); } } catch (IOException e) { handleIOException(e); } catch (AttachmentInvalidException e) { System.err.println("Failed to add avatar attachment for group\": " + e.getMessage()); System.err.println("Aborting sending."); System.exit(1); } catch (GroupNotFoundException e) { handleGroupNotFoundException(e); } catch (EncapsulatedExceptions e) { handleEncapsulatedExceptions(e); } catch (UntrustedIdentityException e) { e.printStackTrace(); } break; case "daemon": if (dBusConn != null) { System.err.println("Stop it."); System.exit(1); } if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } DBusConnection conn = null; try { try { int busType; if (ns.getBoolean("system")) { busType = DBusConnection.SYSTEM; } else { busType = DBusConnection.SESSION; } conn = DBusConnection.getConnection(busType); conn.exportObject(SIGNAL_OBJECTPATH, m); conn.requestBusName(SIGNAL_BUSNAME); } catch (DBusException e) { e.printStackTrace(); System.exit(3); } try { m.receiveMessages(3600, false, new DbusReceiveMessageHandler(m, conn)); } catch (IOException e) { System.err.println("Error while receiving messages: " + e.getMessage()); System.exit(3); } catch (AssertionError e) { handleAssertionError(e); } } finally { if (conn != null) { conn.disconnect(); } } break; } System.exit(0); } finally { if (dBusConn != null) { dBusConn.disconnect(); } } }
From source file:cn.aage.robot.http.util.Args.java
public static <T extends CharSequence> T notEmpty(final T argument, final String name) { if (argument == null) { throw new IllegalArgumentException(name + " may not be null"); }/*w w w . ja v a2s. c om*/ if (TextUtils.isEmpty(argument)) { throw new IllegalArgumentException(name + " may not be empty"); } return argument; }
From source file:com.microsoft.identity.common.test.automation.model.ResultsMapper.java
public static TokenCacheItemReadResult GetTokenCacheItemReadResult(String results) { ReadCacheResult readCacheResult = (ReadCacheResult) ObjectMapper.deserializeJsonStringToObject(results, ReadCacheResult.class); TokenCacheItemReadResult tokenCacheItemReadResult = null; if (readCacheResult != null) { for (String result : readCacheResult.items) { tokenCacheItemReadResult = (TokenCacheItemReadResult) ObjectMapper .deserializeJsonStringToObject(result, TokenCacheItemReadResult.class); if (!TextUtils.isEmpty(tokenCacheItemReadResult.accessToken)) { return tokenCacheItemReadResult; }//from w w w. j av a 2 s . c o m } } return tokenCacheItemReadResult; }
From source file:com.microsoft.identity.common.test.automation.questions.AccessToken.java
@Override public String answeredBy(Actor actor) { String results = Text.of(Results.RESULT_FIELD).viewedBy(actor).asString(); ReadCacheResult readCacheResult = ResultsMapper.GetReadCacheResultFromString(results); String accessToken = null;/*from w w w . j a v a 2 s . c o m*/ if (readCacheResult != null) { for (TokenCacheItemReadResult readResult : readCacheResult.tokenCacheItems) { if (readResult.accessToken != null) { if (TextUtils.isEmpty(clientId) || (!TextUtils.isEmpty(clientId) && clientId.equals(readResult.clientId))) { accessToken = readResult.accessToken; break; } } } } return accessToken; }
From source file:com.nimbits.client.io.http.NimbitsClientImpl.java
public NimbitsClientImpl(final Server theServer) { this.instanceUrl = UrlContainer.getInstance("http://" + theServer.getUrl()); this.server = theServer; this.requestInterceptor = new RequestInterceptor() { @Override/*from w w w. j a v a 2 s . c om*/ public void intercept(RequestInterceptor.RequestFacade request) { if (!TextUtils.isEmpty(server.getAccessToken().getCode())) { request.addHeader(Parameters.token.getText(), theServer.getAccessToken().getCode()); } request.addQueryParam(Parameters.email.getText(), theServer.getEmail().getValue()); } }; }
From source file:com.microsoft.identity.common.test.automation.tasks.AcquireTokenSilent.java
@Override public <T extends Actor> void performAs(T actor) { User user = (User) actor;/* www .j a v a 2 s. co m*/ TokenRequest tokenRequest = user.getSilentTokenRequest(); if (!TextUtils.isEmpty(userIdentifier)) { tokenRequest.setUserIdentitfier(userIdentifier); } if (!TextUtils.isEmpty(uniqueId)) { tokenRequest.setUniqueUserId(uniqueId); } if (!TextUtils.isEmpty(authority)) { tokenRequest.setAuthority(authority); } if (!TextUtils.isEmpty(clientId)) { tokenRequest.setClientId(clientId); } if (!TextUtils.isEmpty(redirectUri)) { tokenRequest.setRedirectUri(redirectUri); } if (!TextUtils.isEmpty(resourceId)) { tokenRequest.setResourceId(resourceId); } tokenRequest.setForceRefresh(forceRefresh); actor.attemptsTo(WaitUntil.the(Main.ACQUIRE_TOKEN_SILENT, isVisible()).forNoMoreThan(10).seconds(), Click.on(Main.ACQUIRE_TOKEN_SILENT), Enter.theValue(user.getSilentTokenRequestAsJson()).into(Request.REQUEST_INFO_FIELD), closeKeyboard, Click.on(Request.SUBMIT_REQUEST_BUTTON)); }
From source file:com.microsoft.identity.common.test.automation.tasks.AcquireToken.java
@Override public <T extends Actor> void performAs(T actor) { User user = (User) actor;//from w w w . j a v a2s. co m TokenRequest tokenRequest = user.getTokenRequest(); if (!TextUtils.isEmpty(prompt)) { tokenRequest.setPromptBehavior(prompt); } if (!TextUtils.isEmpty(userIdentifier)) { tokenRequest.setUserIdentitfier(userIdentifier); } if (!TextUtils.isEmpty(clientId)) { tokenRequest.setClientId(clientId); } if (!TextUtils.isEmpty(redirectUri)) { tokenRequest.setRedirectUri(redirectUri); } tokenRequest.setUseBroker(withBroker); SignInUser signInUser = SignInUser.GetSignInUserByFederationProvider(user.getFederationProvider()); actor.attemptsTo(WaitUntil.the(Main.ACQUIRE_TOKEN_BUTTON, isVisible()).forNoMoreThan(10).seconds(), Click.on(Main.ACQUIRE_TOKEN_BUTTON), Enter.theValue(user.getTokenRequestAsJson()).into(Request.REQUEST_INFO_FIELD), closeKeyboard, WaitUntil.the(Request.SUBMIT_REQUEST_BUTTON, isVisible()).forNoMoreThan(10).seconds(), Click.on(Request.SUBMIT_REQUEST_BUTTON)); // // acquire token does an interactive flow there is no token if (!tokenExists) { // If userIdentifier was not provided in acquire token call , attempt to enter username for sign in if (TextUtils.isEmpty(userIdentifier)) { actor.attemptsTo( WaitUntil.the(SignInPageUserName.USERNAME, isVisible()).forNoMoreThan(10).seconds(), new EnterUserNameForSignInDisambiguation().withBroker(withBroker), WaitUntil.the(SignInPagePassword.PASSWORD, isVisible()).forNoMoreThan(10).seconds()); } // If the user is workplace joined... then they will not need to sign in... because we'll just select that account if (!user.getWorkplaceJoined()) { actor.attemptsTo(signInUser); } } else { // Token already exists, acquire token does a silent flow here. // If userIdentifier was not provided in acquire token call , attempt to enter username for sign in if (TextUtils.isEmpty(userIdentifier)) { actor.attemptsTo(new EnterUserNameForSignInDisambiguation().withBroker(withBroker)); } } }
From source file:com.microsoft.identity.common.test.automation.tasks.ExpireATAndInvalidateRT.java
@Override public <T extends Actor> void performAs(T actor) { User user = (User) actor;// ww w . j a v a 2 s . c o m TokenRequest tokenRequest = user.getTokenRequest(); if (tokenCacheItem != null) { tokenRequest.setAuthority(tokenCacheItem.authority); tokenRequest.setUserIdentitfier(tokenCacheItem.displayableId); tokenRequest.setUniqueUserId(tokenCacheItem.uniqueUserId); tokenRequest.setTenantId(tokenCacheItem.tenantId); tokenRequest.setFamilyClientId(tokenCacheItem.familyClientId); } if (!TextUtils.isEmpty(clientId)) { tokenRequest.setClientId(clientId); } actor.attemptsTo(WaitUntil.the(Main.EXPIRE_AT_INVALIDATE_RT, isVisible()).forNoMoreThan(10).seconds(), Click.on(Main.EXPIRE_AT_INVALIDATE_RT), Enter.theValue(user.getTokenRequestAsJson()).into(Request.REQUEST_INFO_FIELD), closeKeyboard, WaitUntil.the(Request.SUBMIT_REQUEST_BUTTON, isVisible()).forNoMoreThan(10).seconds(), Click.on(Request.SUBMIT_REQUEST_BUTTON)); }
From source file:weavebytes.com.futureerp.activities.RegistrationActivity.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btnregister: username = edtname.getText().toString(); password = edtpass.getText().toString(); email = edtmail.getText().toString(); if (TextUtils.isEmpty(username)) { edtname.setError(username);//ww w. j a v a 2s .c o m } else if (TextUtils.isEmpty(password)) { edtpass.setError("Enter Password"); } else if (TextUtils.isEmpty(email)) { edtmail.setError("Enter Password"); } else SendRegRequest(); } }
From source file:heybot.heybot.java
private static void start(CommandLine line) { String[] args = line.getArgs(); if (args.length == 1) { processOperation(args[0]);//ww w .ja v a 2 s . co m } else { String doOptionValue = line.getOptionValue("do"); if (!TextUtils.isEmpty(doOptionValue)) { processOperation(doOptionValue); } else { System.err.println("Ooops! Unrecognized argument. Please refer to documentation."); } } }