List of usage examples for org.apache.commons.lang3 StringUtils isEmpty
public static boolean isEmpty(final CharSequence cs)
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0.
From source file:com.adguard.android.filtering.api.HttpServiceClient.java
/** * Posts request with specified parameters to url. * * @param uploadUrl URL to send POST request to * @param data POST body//from w w w.j av a 2s. c om * @return Response string * @throws IOException */ protected static String postData(String uploadUrl, String data) throws IOException { LOG.debug("Sending HTTP POST request to {}. Length={}", uploadUrl, StringUtils.length(data)); final String response = UrlUtils.postRequest(new URL(uploadUrl), data, "utf-8", "application/x-www-form-urlencoded", true, READ_TIMEOUT, CONNECTION_TIMEOUT); if (StringUtils.isEmpty(response)) { LOG.error("Response for {} is empty", uploadUrl); throw new IOException("Response is empty."); } LOG.debug("Got response: {}", response); return response; }
From source file:com.epam.dlab.auth.rest.UserSessionDurationAuthorizer.java
@Override public boolean authorize(UserInfo principal, String role) { if (SHORT_USER_SESSION_DURATION.equalsIgnoreCase(role)) { try {/*from ww w . jav a 2s .c o m*/ String refreshToken = principal.getKeys().get("refresh_token"); String createdDateOfRefreshToken = principal.getKeys().get("created_date_of_refresh_token"); if (StringUtils.isEmpty(refreshToken)) { log.info("Refresh token is empty for user {}", principal.getName()); return false; } if (StringUtils.isEmpty(createdDateOfRefreshToken)) { log.info("Created date for refresh token is empty for user {}", principal.getName()); return false; } log.debug("refresh token requested {} and current date is {}", new Date(Long.valueOf(createdDateOfRefreshToken)), new Date()); long passedTime = System.currentTimeMillis() - Long.valueOf(createdDateOfRefreshToken); log.info("Passed time of session for user {} is {} milliseconds", principal.getName(), passedTime); if (passedTime > maxSessionDurabilityMilliseconds) { silentCallbackExecution(principal); log.info("Re-login required for user {}", principal.getName()); return false; } return true; } catch (RuntimeException e) { log.error("Cannot verify durability of session for user {}", principal.getName(), e); return false; } } return true; }
From source file:jp.mathes.databaseWiki.wiki.DbwLinkPlugin.java
@Override @SuppressWarnings("unchecked") public void process(final Document doc, final String fieldname, final String user, final String password, final Backend backend) { Field<String> field = doc.getAllFields().get(fieldname); String renderedText = field.getValue(); Matcher matcher = DbwLinkPlugin.REGEX.matcher(renderedText); while (matcher.find()) { String path = ""; String prefix = "."; String description = matcher.group(4); if (StringUtils.isEmpty(matcher.group(1))) { if (StringUtils.isEmpty(matcher.group(2))) { path = matcher.group(3); prefix = ".."; } else { path = String.format("%s/%s", matcher.group(2), matcher.group(3)); prefix = "../.."; }/* ww w . j a v a 2 s. co m*/ } else { path = String.format("%s/%s/%s", matcher.group(1), matcher.group(2), matcher.group(3)); prefix = "../../.."; } renderedText = renderedText.replace(matcher.group(0), String.format("<a href=\"%s/%s/view\">%s</a>", prefix, path, StringUtils.isEmpty(description) ? path : description)); } field.setValue(renderedText); }
From source file:com.micromux.cassandra.jdbc.CollectionsTest.java
/** * @throws java.lang.Exception//from w w w . j av a2 s .c om */ @BeforeClass public static void setUpBeforeClass() throws Exception { // configure OPTIONS if (!StringUtils.isEmpty(TRUST_STORE)) { OPTIONS = String.format("trustStore=%s&trustPass=%s", URLEncoder.encode(TRUST_STORE), TRUST_PASS); } Class.forName("com.micromux.cassandra.jdbc.CassandraDriver"); String URL = String.format("jdbc:cassandra://%s:%d/%s?%s&version=%s", HOST, PORT, SYSTEM, OPTIONS, CQLV3); con = DriverManager.getConnection(URL); if (LOG.isDebugEnabled()) LOG.debug("URL = '{}'", URL); Statement stmt = con.createStatement(); // Use Keyspace String useKS = String.format("USE %s;", KEYSPACE); // Drop Keyspace String dropKS = String.format("DROP KEYSPACE %s;", KEYSPACE); try { stmt.execute(dropKS); } catch (Exception e) { /* Exception on DROP is OK */} // Create KeySpace String createKS = String.format( "CREATE KEYSPACE %s WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", KEYSPACE); // String createKS = String.format("CREATE KEYSPACE %s WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1;",KEYSPACE); if (LOG.isDebugEnabled()) LOG.debug("createKS = '{}'", createKS); stmt = con.createStatement(); stmt.execute("USE " + SYSTEM); stmt.execute(createKS); stmt.execute(useKS); // Create the target Table (CF) String createTable = "CREATE TABLE testcollection (" + " k int PRIMARY KEY," + " L list<bigint>," + " M map<double, boolean>, M2 map<text, timestamp>, S set<text>" + ") ;"; if (LOG.isDebugEnabled()) LOG.debug("createTable = '{}'", createTable); stmt.execute(createTable); stmt.close(); con.close(); // open it up again to see the new TABLE URL = String.format("jdbc:cassandra://%s:%d/%s?%s&version=%s", HOST, PORT, KEYSPACE, OPTIONS, CQLV3); con = DriverManager.getConnection(URL); if (LOG.isDebugEnabled()) LOG.debug("URL = '{}'", URL); Statement statement = con.createStatement(); String insert = "INSERT INTO testcollection (k,L) VALUES( 1,[1, 3, 12345]);"; statement.executeUpdate(insert); String update1 = "UPDATE testcollection SET S = {'red', 'white', 'blue'} WHERE k = 1;"; String update2 = "UPDATE testcollection SET M = {2.0: true, 4.0: false, 6.0 : true} WHERE k = 1;"; statement.executeUpdate(update1); statement.executeUpdate(update2); if (LOG.isDebugEnabled()) LOG.debug("Unit Test: 'CollectionsTest' initialization complete.\n\n"); }
From source file:com.webbfontaine.valuewebb.search.ShippingLinesFinder.java
public List getResultList() { if (StringUtils.isEmpty(rimmCriteria.getActiveFor())) { return emptyResultList; }/*from w w w .j a v a 2 s .com*/ if (resultList != null) { return resultList; } select(); return resultList; }
From source file:in.bookmylab.controllers.Bookings.java
@Action @Authorize// w ww .j av a 2s . c o m public void getBooking() throws IOException { try { String bid = getRequestParameter("bid"); String lab = getRequestParameter("lab"); Object booking = null; if (!StringUtils.isEmpty(bid) && !StringUtils.isEmpty(lab)) { Long bookingId = Long.parseLong(bid); if (ResourceType.sem.name().equalsIgnoreCase(lab)) { // TODO } else if (ResourceType.spm.name().equalsIgnoreCase(lab)) { booking = JpaDAO.getInstance().getSpmByBookingId(bookingId); if (!canCurrentUserView(((SpmLabBooking) booking).booking)) { throw new AppException("Cannot access the requested booking!"); } } else if (ResourceType.xrd.name().equalsIgnoreCase(lab)) { booking = JpaDAO.getInstance().getXrdByBookingId(bookingId); if (!canCurrentUserView(((XrdLabBooking) booking).booking)) { throw new AppException("Cannot access the requested booking!"); } } else if (ResourceType.other.name().equalsIgnoreCase(lab)) { // TODO } else { throw new IllegalArgumentException("Invalid resource type: " + lab); } } sendJsonResponse(Status.OK, booking); } catch (Exception e) { handleActionError(e); } }
From source file:com.gdo.project.util.StclUtils.java
public static <S extends _PStencil<StclContext, S>> String expand(StclContext stclContext, String text, _PStencil<StclContext, S> plugged) { if (_pattern == null) return text; // decode /*from w w w . j a v a 2 s . c om*/ String str = text.replaceAll("%A3", ""); // name found then no extension PatternMatcher matcher = new Perl5Matcher(); PatternMatcherInput input = new PatternMatcherInput(str); if (!matcher.contains(input, _pattern)) return str; // extends all name StringBuffer res = new StringBuffer(); MatchResult match; do { match = matcher.getMatch(); res.append(match.group(1)); String path = match.group(3); if (!StringUtils.isEmpty(path)) { res.append("<$stencil path=\"").append(path).append("\" mode=\"label\"/>"); } input = new PatternMatcherInput(match.group(5)); } while (matcher.contains(input, _pattern)); return res.append(match.group(5)).toString(); }
From source file:de.micromata.genome.gwiki.web.tags.GWikiTagRenderUtils.java
public static void renderAttribute(Object tag, Pair<Field, ? extends Annotation> p, StringBuilder sb) { Object value = PrivateBeanUtils.readField(tag, p.getFirst()); if (value == null) { return;//from w ww . j ava2 s. c om } if (sb.length() > 0) { sb.append(" "); } ElementProperty an = (ElementProperty) p.getSecond(); String svalue = value.toString(); if (an.ignoreValue().length() > 0 && an.ignoreValue().equals(svalue) == true) { return; } String name = an.name(); if (StringUtils.isEmpty(name) == true) { name = p.getFirst().getName(); } sb.append(name).append("=").append("\"").append(StringEscapeUtils.escapeXml(ObjectUtils.toString(value))) .append("\""); }
From source file:com.reversemind.hypergate.server.HyperGateServerAdvertiser.java
/** * @param builder//w w w .ja va 2 s . c o m */ public HyperGateServerAdvertiser(ServerFactory.Builder builder) { super(builder); if (StringUtils.isEmpty(builder.getZookeeperHosts())) { throw new RuntimeException("Need zookeeper connection string"); } this.zookeeperHosts = builder.getZookeeperHosts(); if (StringUtils.isEmpty(builder.getServiceBasePath())) { throw new RuntimeException("Need zookeeper base path string"); } this.serviceBasePath = builder.getServiceBasePath(); this.metadata = new ServerMetadata(this.getName(), this.getInstanceName(), this.getHost(), this.getPort(), this.metrics); this.useMetrics = builder.isUseMetrics(); if (builder.isUseMetrics()) { this.periodPublishMetrics = builder.getPeriodPublishMetrics(); LOG.debug("builder.getPeriodPublishMetrics() == " + builder.getPeriodPublishMetrics()); if (builder.getPeriodPublishMetrics() < 0) { this.periodPublishMetrics = 1000; //ms } LOG.debug("this.periodPublishMetrics == " + this.periodPublishMetrics); this.metricsUpdateTask = new MetricsUpdateTask(); this.timer = new Timer(); this.timer.schedule(this.metricsUpdateTask, this.periodPublishMetrics, this.periodPublishMetrics); } }