List of usage examples for java.lang String isEmpty
public boolean isEmpty()
From source file:hoot.services.utils.PostgresUtils.java
static Map<String, String> parseTags(String tagsStr) { Map<String, String> tagsMap = new HashMap<>(); if ((tagsStr != null) && (!tagsStr.isEmpty())) { Pattern regex = Pattern.compile("(\"[^\"]*\")=>(\"(?:\\\\.|[^\"\\\\]+)*\"|[^,\"]*)"); Matcher regexMatcher = regex.matcher(tagsStr); while (regexMatcher.find()) { String key = regexMatcher.group(1); key = StringUtils.removeStart(key, "\""); key = StringUtils.removeEnd(key, "\""); String val = regexMatcher.group(2); val = StringUtils.removeStart(val, "\""); val = StringUtils.removeEnd(val, "\""); tagsMap.put(key, val); }/* w ww . j a v a 2 s . c o m*/ } return tagsMap; }
From source file:org.drugis.addis.config.controller.IndexController.java
private static String getPataviMcdaWsUri() { try {// w w w .j ava 2 s .c om String uri; String envUri = System.getenv("ADDIS_CORE_PATAVI_MCDA_WS_URI"); if (envUri != null && !envUri.isEmpty()) { uri = envUri; } else { uri = DEFAULT_PATAVI_MCDA_WS_URI; } logger.info("PATAVI_MCDA_WS_URI: " + uri); return uri; } catch (Exception e) { logger.error( "can not find env variable PATAVI_MCDA_WS_URI fallback to using DEFAULT_PATAVI_MCDA_WS_URI: " + DEFAULT_PATAVI_MCDA_WS_URI); return DEFAULT_PATAVI_MCDA_WS_URI; } }
From source file:com.claim.support.FtpUtil.java
public static void ftpCreateDirectoryTree(FTPClient client, String dirTree) throws IOException { boolean dirExists = true; //tokenize the string and attempt to change into each directory level. If you cannot, then start creating. String[] directories = dirTree.split("/"); for (String dir : directories) { if (!dir.isEmpty()) { if (dirExists) { dirExists = client.changeWorkingDirectory(dir); }// ww w .j a v a 2 s . com if (!dirExists) { if (!client.makeDirectory(dir)) { throw new IOException("Unable to create remote directory '" + dir + "'. error='" + client.getReplyString() + "'"); } if (!client.changeWorkingDirectory(dir)) { throw new IOException("Unable to change into newly created remote directory '" + dir + "'. error='" + client.getReplyString() + "'"); } } } } }
From source file:com.sap.prd.mobile.ios.mios.Forker.java
static int forkProcess(final PrintStream out, final File executionDirectory, final String... args) throws IOException { if (out == null) throw new IllegalArgumentException("Print stream for log handling was not provided."); if (args == null || args.length == 0) throw new IllegalArgumentException("No arguments has been provided."); for (final String arg : args) if (arg == null || arg.isEmpty()) throw new IllegalArgumentException( "Invalid argument '" + arg + "' provided with arguments '" + Arrays.asList(args) + "'."); final ProcessBuilder builder = new ProcessBuilder(args); if (executionDirectory != null) builder.directory(executionDirectory); builder.redirectErrorStream(true);//from www .ja va 2 s. c o m InputStream is = null; // // TODO: check if there is any support for forking processes in // maven/plexus // try { final Process process = builder.start(); is = process.getInputStream(); handleLog(is, out); return process.waitFor(); } catch (InterruptedException e) { throw new RuntimeException(e.getClass().getName() + " caught during while waiting for a forked process. This exception is not expected to be caught at that time.", e); } finally { // // Exception raised during close operation below are not reported. // That is actually bad. // We do not have any logging facility here and we cannot throw the // exception since this would swallow any // other exception raised in the try block. // May be we should revisit that ... // IOUtils.closeQuietly(is); } }
From source file:interactivespaces.workbench.project.constituent.BaseProjectConstituentBuilder.java
/** * Convenience function to help more easily build constituent parts. * * @param resourceElement/*from w w w.j ava 2s . c om*/ * input element * @param namespace * XML namespace for property name * @param propertyName * property name to extract * @param fallback * fallback value to use if none supplied * * @return property value, else fallback */ public static String getChildTextNormalize(Element resourceElement, Namespace namespace, String propertyName, String fallback) { String value = resourceElement.getChildTextNormalize(propertyName, namespace); return (value == null || (value.isEmpty() && fallback != null)) ? fallback : value; }
From source file:Main.java
private static boolean validateUserXML(Document doc) { NodeList nodeList = null;//from w w w . jav a 2 s .c o m // Check the elements and values exist nodeList = doc.getElementsByTagName("user"); if (nodeList.getLength() != 1) { return false; } // Check that email element exists nodeList = doc.getElementsByTagName("username"); if (nodeList.getLength() != 1) { return false; } // Check that value is not null or empty String username = getValue((Element) doc.getElementsByTagName("user").item(0), "username"); if (username == null || username.isEmpty()) { return false; } // Check that email element exists nodeList = doc.getElementsByTagName("password"); if (nodeList.getLength() != 1) { return false; } // Check that value is not null or empty String password = getValue((Element) doc.getElementsByTagName("user").item(0), "password"); if (password == null || password.isEmpty()) { return false; } return true; }
From source file:Main.java
/** * Removes invalid XML characters from the input text and then replaces XML special character <code>&</code>, * <code><</code>, <code>></code>, <code>"</code>, <code>'</code> with corresponding entity references. * * @param text The input that needs to be escaped. May be null. * @return String with the special characters replaced with entity references. May be null. *///www . j av a 2 s . co m public static String escapeSpecialCharacters(String text) { text = removeInvalidXMLChars(text); if (text == null || text.isEmpty()) { return text; } final StringBuilder sb = new StringBuilder(text.length()); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { case '&': sb.append("&"); break; case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '\"': sb.append("""); break; case '\'': sb.append("'"); break; case '\n': sb.append("
"); break; case '\r': sb.append("
"); break; default: sb.append(c); } } return sb.toString(); }
From source file:com.reprezen.swagedit.validation.ValidationUtil.java
public static int getLine(JsonNode error, Node yamlTree) { if (!error.has("instance") || !error.get("instance").has("pointer")) return 1; String path = error.get("instance").get("pointer").asText(); if (path == null || path.isEmpty()) return 1; path = path.substring(1, path.length()); String[] strings = path.split("/"); if (yamlTree instanceof MappingNode) { MappingNode mn = (MappingNode) yamlTree; Node findNode = findNode(mn, Arrays.asList(strings)); if (findNode != null) { return findNode.getStartMark().getLine() + 1; }/*from w ww .j av a 2 s . co m*/ } return 1; }
From source file:dk.netarkivet.harvester.webinterface.HarvestChannelAction.java
/** * This method processes the request to determine which action it corresponds to and passes the request along * accordingly. Available actions are://from w w w. ja v a 2s.c om * <ul> * <li>create harvest channel</li> * <li>map harvest definition to channel</li> * </ul> * * @param context the original servlet context of the request. * @param i18n the internationalisation to be used. * @throws ForwardedToErrorPage if an exception is thrown while carrying out the action. */ public static void processRequest(PageContext context, I18n i18n) throws ForwardedToErrorPage { ArgumentNotValid.checkNotNull(context, "PageContext context"); ArgumentNotValid.checkNotNull(i18n, "I18n i18n"); log.debug("Processing request"); HttpServletRequest request = (HttpServletRequest) context.getRequest(); try { String action = request.getParameter(ACTION); if (action == null || action.isEmpty()) { return; } switch (ActionType.valueOf(action)) { case createHarvestChannel: String name = request.getParameter(CHANNEL_NAME); HTMLUtils.forwardOnEmptyParameter(context, CHANNEL_NAME); HarvestChannelDAO dao = HarvestChannelDAO.getInstance(); dao.create(new HarvestChannel(name, false, false, request.getParameter(COMMENTS))); break; case mapHarvestToChannel: long harvestId = Long.parseLong(request.getParameter(HARVEST_ID)); long channelId = Long.parseLong(request.getParameter(CHANNEL_ID)); HarvestChannelDAO hcDao = HarvestChannelDAO.getInstance(); HarvestDefinitionDAO hdDao = HarvestDefinitionDAO.getInstance(); hdDao.mapToHarvestChannel(harvestId, hcDao.getById(channelId)); break; default: } } catch (Throwable e) { HTMLUtils.forwardWithErrorMessage(context, i18n, e, "errormsg;harvest.channel.create.error"); throw new ForwardedToErrorPage("Error in Harvest Channels", e); } }