List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.glaf.mail.util.MailUtils.java
public static String getMailText(int type, String text) { String mailText = ""; if (text == null || text.trim().equalsIgnoreCase("null")) { return mailText; }/*from w w w . ja v a2 s . c o m*/ String newline = System.getProperty("line.separator"); StringBuffer buffer = new StringBuffer(); buffer.append(newline); buffer.append(newline); if (type == 1) { buffer.append(newline); buffer.append(newline); buffer.append("=================== ??===================="); buffer.append(newline); } if (type == 2) { buffer.append(newline); buffer.append("********************??**********************"); } StringTokenizer token = new StringTokenizer(text, "\r\n"); while (token.hasMoreTokens()) { String temp = token.nextToken(); buffer.append(newline); buffer.append(">").append(temp); } buffer.append(newline); buffer.append(newline); buffer.append("= = = = = = = = = = = = = = = = = = = = = = = = = = = = ="); buffer.append(newline); return buffer.toString(); }
From source file:de.pawlidi.openaletheia.utils.AletheiaUtils.java
/** * /*from w w w .j a v a 2 s. c o m*/ * @return */ public static String getLinuxMacAddress() { String ipConfigResponse = executeCommand("ifconfig"); if (ipConfigResponse == null) { ipConfigResponse = executeCommand("/sbin/ifconfig"); if (ipConfigResponse == null) { return null; } } String localHost = getLocalhostAddress(); if (localHost == null) { return null; } StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); String lastMacAddress = null; while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); boolean containsLocalHost = line.indexOf(localHost) >= 0; if ((containsLocalHost) && (lastMacAddress != null)) { return lastMacAddress; } int macAddressPosition = line.indexOf("HWaddr"); if (macAddressPosition > 0) { String macAddressCandidate = line.substring(macAddressPosition + 6).trim(); if (isMacAddressCandidate(macAddressCandidate)) { lastMacAddress = normalizeMacAddress(macAddressCandidate); } } } return null; }
From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java
public static void pasteString(String s, SpreadSheet spreadsheet, int row0, int col0) { StringTokenizer st = new StringTokenizer(s, "\n"); int row = row0;//,maxRow=spreadsheet.getRowCount()-1; while (st.hasMoreTokens()/*&&row<=maxRow*/) //maxRow useless, maxRow increased automatically pasteStringLine(st.nextToken(), spreadsheet, row++, col0); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.penntree.PennTreeUtils.java
public static PennTreeNode parsePennTree(String aTree) { StringTokenizer st = new StringTokenizer(aTree, "() ", true); PennTreeNode root = null;/*from ww w . ja va2s.c om*/ Stack<PennTreeNode> stack = new Stack<PennTreeNode>(); boolean seenLabel = false; while (st.hasMoreTokens()) { String t = st.nextToken().trim(); if (t.length() == 0) { // Skip } else if ("(".equals(t)) { PennTreeNode n = new PennTreeNode(); stack.push(n); if (root == null) { root = n; } seenLabel = false; } else if (")".equals(t)) { PennTreeNode n = stack.pop(); if (!stack.isEmpty()) { PennTreeNode p = stack.peek(); p.addChild(n); } } else if (seenLabel) { // If the node has two labels, its a leaf, add a new terminal node then. PennTreeNode p = stack.peek(); PennTreeNode n = new PennTreeNode(); n.setLabel(t); p.addChild(n); } else { PennTreeNode n = stack.peek(); n.setLabel(t); seenLabel = true; } } return root; }
From source file:de.elbe5.base.util.StringUtil.java
public static String toHtmlText(String src) { if (src == null) { return ""; }/* w ww . j av a 2 s . c om*/ if (src.indexOf('\n') == -1) return StringEscapeUtils.escapeHtml4(src); StringTokenizer stk = new StringTokenizer(src, "\n", true); if (stk.countTokens() == 0) return ""; StringBuilder sb = new StringBuilder(); String token; while (stk.hasMoreTokens()) { token = stk.nextToken(); if (token.equals("\n")) sb.append("\n<br/>\n"); else sb.append(StringEscapeUtils.escapeHtml4(token)); } return sb.toString(); }
From source file:Main.java
@NonNull private static List<String> parseGradientValues(String image) { if (TextUtils.isEmpty(image)) { return null; }// w w w .j a v a2s .c om image.trim(); if (image.startsWith("linear-gradient")) { String valueStr = image.substring(image.indexOf("(") + 1, image.lastIndexOf(")")); StringTokenizer tokenizer = new StringTokenizer(valueStr, ","); List<String> values = new ArrayList<>(); String temp = null; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.contains("(")) { temp = token + ","; continue; } if (token.contains(")")) { temp += token; values.add(temp); temp = null; continue; } if (temp != null) { temp += (token + ","); continue; } values.add(token); } return values; } return null; }
From source file:SocketFetcher.java
/** * Parse a string into whitespace separated tokens and return the tokens in an * array.//from w w w .jav a2 s . c om */ private static String[] stringArray(String s) { StringTokenizer st = new StringTokenizer(s); List tokens = new ArrayList(); while (st.hasMoreTokens()) tokens.add(st.nextToken()); return (String[]) tokens.toArray(new String[tokens.size()]); }
From source file:com.ikon.extractor.RegisteredExtractors.java
/** * Check for registered text extractor/*from ww w .ja va 2s . co m*/ */ public static boolean isRegistered(String className) { List<String> classes = new ArrayList<String>(); if (Config.MANAGED_TEXT_EXTRACTION || Config.REPOSITORY_NATIVE) { classes = Config.REGISTERED_TEXT_EXTRACTORS; } else { try { RepositoryConfig rc = JcrRepositoryModule.getRepositoryConfig(); WorkspaceConfig wc = rc.getWorkspaceConfig(rc.getDefaultWorkspaceName()); SearchConfig sc = wc.getSearchConfig(); if (sc != null) { String tfClasses = (String) sc.getParameters().get("textFilterClasses"); StringTokenizer tokenizer = new StringTokenizer(tfClasses, ", \t\n\r\f"); while (tokenizer.hasMoreTokens()) { String clazz = tokenizer.nextToken(); classes.add(clazz); } } } catch (ConfigurationException e) { log.warn(e.getMessage(), e); } } for (String name : classes) { if (name.equals(className)) { return true; } } return false; }
From source file:AnimatedMetadataGraph.java
public static String getParentPath(String childPath) { if (!childPath.equals("/")) { Vector<String> pathElements = new Vector<String>(); StringTokenizer tokenizer = new StringTokenizer(childPath, "/"); while (tokenizer.hasMoreTokens()) pathElements.add(tokenizer.nextToken()); StringBuffer parentPath = new StringBuffer().append("/"); for (int i = 0; i < pathElements.size() - 1; i++) parentPath.append(pathElements.get(i)).append("/"); return parentPath.toString(); }/*w ww. j av a 2 s. c o m*/ return null; }
From source file:at.jps.sanction.core.util.TokenTool.java
public static List<String> getTokenList(final String text, final String delimiters, final String deadCharacters, final int minlength, final Collection<String> excludeList, final boolean filterTokens) { final List<String> textTokens = new ArrayList<>(10); if ((text != null) && (text.length() > minlength)) { String oriText = text.toUpperCase(); // remove dead characters if (deadCharacters != null) { for (int i = 0; i < deadCharacters.length(); i++) { oriText = StringUtils.remove(oriText, deadCharacters.charAt(i)); // oriText.replace(deadCharacters.charAt(i), ' '); }/* www . j ava 2 s . c om*/ } // TODO: transliterate // remove stopwords - !! dead characters MUST NOT exist in stopwords !! // must be sorted by length !! if (!filterTokens) { if (excludeList != null) { for (final String stopword : excludeList) { oriText = oriText.replace(stopword.toUpperCase(), ""); } } } // maybe preserve original formatted text ? // StrTokenizer textTokenizer = new StrTokenizer(oriText, delimiters); // textTokenizer.setEmptyTokenAsNull(false); // textTokenizer.setIgnoreEmptyTokens(true); // feature !! if (delimiters != null) { final StringTokenizer textTokenizer = new StringTokenizer(oriText, delimiters); while (textTokenizer.hasMoreTokens()) { final String token = textTokenizer.nextToken().trim(); if ((token != null) && (token.length() >= minlength)) { // TODO: clear tokens ( deadchars...) if (filterTokens) { if ((excludeList == null) || (!excludeList.contains(token))) { if (!textTokens.contains(token)) { textTokens.add(token); } } } else { if (!textTokens.contains(token)) { textTokens.add(token); } } } } } else { textTokens.add(oriText); } } return textTokens; }