List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:org.sakaiproject.imagegallery.springutil.SqlScriptParser.java
/** * Parse a line of text to remove comments. * @param line The line to parse. The string must not have any new line, * carriage return, or form feed characters. It also may not * contain a double-quote outside of a string literal, and the * statement delimiter character may only appear at the end of * the line./*from w ww . j a v a 2s .com*/ * @param sql String buffer that stores the result, which is appended to the * end. When the method returns, it will contain the trimmed line * with comments removed. If the line contains no usable SQL * fragment, nothing is appended. * @param lineNumber Line number used for exceptions. * @throws ParseException * @throws IllegalArgumentException if the line is null or contains one of * the line terminating characters mentioned above. * @throws UncategorizedDataAccessException if parsing fails for some other reason. */ private static void parseLine(String line, StringBuffer sql, int lineNumber, char statementDelimiter) { // Parse line looking for single quote string delimiters. Anything // that's part of a string just passes through. StringTokenizer quoteTokenizer = new StringTokenizer(line, "'", true); // true if we're parsing through a string literal. boolean inLiteral = false; while (quoteTokenizer.hasMoreTokens()) { String token = quoteTokenizer.nextToken(); if (token.equals("'")) { // Token is a string delimiter. Toggle "inLiteral" flag. inLiteral = !inLiteral; } else if (!inLiteral) { // Look for EOL comments. int commentIndex = indexOfComment(token); if (commentIndex >= 0) { // Truncate token to the comment marker. token = token.substring(0, commentIndex).trim(); } // Thwart any attempt to use double-quote outside of a string // literal. if (token.indexOf("\"") >= 0) { throw new RuntimeException( new ParseException("Double quote character" + " cannot be used in a string literal.", token.indexOf("\""))); } // Thwart any attempt to have the statement delimiter embedded // in a line. Not supported at this point. int statementEndIndex = token.indexOf(statementDelimiter); if (statementEndIndex >= 0 && statementEndIndex != (token.length() - 1)) { throw new RuntimeException(new ParseException( "SQL statement delimiter" + " embedded in a line. (Not supported at this point)", statementEndIndex)); } // If we've hit a comment, we're done with this line. Just // append the token and break out. if (commentIndex >= 0) { sql.append(token); break; } } // Else, we're in a string literal. Just let it pass through. sql.append(token); } if (inLiteral) { // If the inLiteral flag is set here, the line has an unterminated // string literal. throw new RuntimeException(new ParseException("Unterminated string literal.", 0)); } }
From source file:com.epam.reportportal.apache.http.conn.ssl.AbstractVerifier.java
public static String[] getCNs(final X509Certificate cert) { final LinkedList<String> cnList = new LinkedList<String>(); /*/*from w w w . ja v a 2s. co m*/ Sebastian Hauer's original StrictSSLProtocolSocketFactory used getName() and had the following comment: Parses a X.500 distinguished name for the value of the "Common Name" field. This is done a bit sloppy right now and should probably be done a bit more according to <code>RFC 2253</code>. I've noticed that toString() seems to do a better job than getName() on these X500Principal objects, so I'm hoping that addresses Sebastian's concern. For example, getName() gives me this: 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d whereas toString() gives me this: EMAILADDRESS=juliusdavies@cucbc.com Looks like toString() even works with non-ascii domain names! I tested it with "花子.co.jp" and it worked fine. */ final String subjectPrincipal = cert.getSubjectX500Principal().toString(); final StringTokenizer st = new StringTokenizer(subjectPrincipal, ",+"); while (st.hasMoreTokens()) { final String tok = st.nextToken().trim(); if (tok.length() > 3) { if (tok.substring(0, 3).equalsIgnoreCase("CN=")) { cnList.add(tok.substring(3)); } } } if (!cnList.isEmpty()) { final String[] cns = new String[cnList.size()]; cnList.toArray(cns); return cns; } else { return null; } }
From source file:eu.irreality.age.SwingAetheriaGameLoaderInterface.java
public static void setLookAndFeel() { try {// w w w.j av a 2 s . c o m boolean setLAF = true; setLAF = false; //pasamos del native look and feel. //check java version and native look and feel: seems that GTK look and feel is broken for versions < 1.6 if (UIManager.getSystemLookAndFeelClassName().indexOf("gtk") >= 0) { String javaVersion = System.getProperty("java.version"); StringTokenizer st = new StringTokenizer(javaVersion, ".-_"); int firstNum; int secondNum; try { firstNum = Integer.valueOf(st.nextToken()).intValue(); secondNum = Integer.valueOf(st.nextToken()).intValue(); /* if ( firstNum <= 1 && secondNum <= 5 ) setLAF = false; */ //don't use GTK l&f at all setLAF = false; } catch (Exception exc) { ; //version unreadable: bah, set the look and feel and pray. } } if (setLAF) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } catch (Exception ulafe) { ulafe.printStackTrace(); } }
From source file:PackageUtils.java
public static String getNamespace(String packageName) { if (packageName == null || packageName.length() == 0) { return null; }//from w ww. j a va2 s. co m StringTokenizer tokenizer = new StringTokenizer(packageName, "."); String[] tokens; if (tokenizer.countTokens() == 0) { tokens = new String[0]; } else { tokens = new String[tokenizer.countTokens()]; for (int i = tokenizer.countTokens() - 1; i >= 0; i--) { tokens[i] = tokenizer.nextToken(); } } StringBuffer namespace = new StringBuffer("http://"); String dot = ""; for (int i = 0; i < tokens.length; i++) { if (i == 1) { dot = "."; } namespace.append(dot + tokens[i]); } namespace.append('/'); return namespace.toString(); }
From source file:gmgen.plugin.PlayerCharacterOutput.java
private static String getWeaponType(Equipment eq, boolean primary) { StringBuilder sb = new StringBuilder(); StringTokenizer aTok = new StringTokenizer(SettingsHandler.getGame().getWeaponTypes(), "|", false); while (aTok.countTokens() >= 2) { final String aType = aTok.nextToken(); final String abbrev = aTok.nextToken(); if (eq.isType(aType, true)) { sb.append(abbrev);//from ww w. j a v a 2s .co m } } return sb.toString(); }
From source file:com.sslexplorer.input.tags.VariablesTag.java
/** * Method to generate the Replacement Variable Chooser Fragment. * //from w w w. jav a 2s .c om * @param titleKey * @param pageContext * @param bundle * @param locale * @param inputId * @param variables * @param includeSession * @param includeUserAttributes * @param includeRequest * @return String * @throws JspException */ public static String generateReplacementVariableChooserFragment(String titleKey, PageContext pageContext, String bundle, String locale, String inputId, String variables, boolean includeSession, boolean includeUserAttributes, boolean includeRequest) throws JspException { StringBuffer buf = new StringBuffer(); String title = null; if (titleKey != null) { title = TagUtils.getInstance().message(pageContext, bundle, locale, titleKey, new String[] {}); } if (title == null) { title = TagUtils.getInstance().message(pageContext, bundle, locale, "replacementVariablesChooser.title", new String[] {}); if (title == null) { title = "Replacement Variables"; } } buf.append("<div class=\"component_replacementVariablesToggle\">"); // buf.append("<input type=\"button\" // onclick=\"toggleAndPositionBelow(document.getElementById('replacementVariablesChooser"); // buf.append(inputId); // buf.append("'), document.getElementById('"); // buf.append(inputId); // buf.append("'))\" "); // buf.append("value=\"${}\"/>"); buf.append("<img onclick=\"togglePopupBelowLeft(document.getElementById('replacementVariablesChooser"); buf.append(inputId); buf.append("'), document.getElementById('"); buf.append(inputId); buf.append("'))\" "); buf.append("src=\""); buf.append(CoreUtil.getThemePath(pageContext.getSession())); buf.append("/images/variables.gif\"/>"); buf.append("</div>"); buf.append("<div id=\"replacementVariablesChooser"); buf.append(inputId); buf.append("\" style=\"position:absolute;display: none;overflow:visible;top:4px;left:4px;z-index:900;\">"); buf.append("<div class=\"replacementVariablesMain\">"); buf.append("<div class=\"replacementVariablesTitleBar\">"); buf.append("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"); buf.append("<tr><td class=\"title\">"); buf.append(title); buf.append("</td><td class=\"close\"><img src=\""); buf.append(CoreUtil.getThemePath(pageContext.getSession())); buf.append("/images/actions/erase.gif\" "); buf.append("onclick=\"document.getElementById('"); buf.append(inputId); buf.append("').value = ''\"/><img src=\""); buf.append(CoreUtil.getThemePath(pageContext.getSession())); buf.append("/images/actions/closeReplacementVariables.gif\" "); buf.append("onclick=\"togglePopup(document.getElementById('replacementVariablesChooser"); buf.append(inputId); buf.append("'))\"/>"); buf.append("</td></tr></table></div><div class=\"replacementVariablesContent\">"); buf.append("<ul>"); if (variables != null) { StringTokenizer t = new StringTokenizer(variables, ","); while (t.hasMoreTokens()) { String n = t.nextToken(); addVariable(n, n, buf, pageContext, bundle, locale, inputId); } } if (includeSession) { addVariable("session:username", null, buf, pageContext, bundle, locale, inputId); addVariable("session:password", null, buf, pageContext, bundle, locale, inputId); addVariable("session:email", null, buf, pageContext, bundle, locale, inputId); addVariable("session:fullname", null, buf, pageContext, bundle, locale, inputId); addVariable("session:clientProxyURL", null, buf, pageContext, bundle, locale, inputId); } if (includeRequest) { addVariable("request:serverName", null, buf, pageContext, bundle, locale, inputId); addVariable("request:serverPort", null, buf, pageContext, bundle, locale, inputId); addVariable("request:userAgent", null, buf, pageContext, bundle, locale, inputId); } if (includeUserAttributes) { Collection<PropertyDefinition> l; try { for (PropertyClass propertyClass : PropertyClassManager.getInstance().getPropertyClasses()) { if (propertyClass instanceof AttributesPropertyClass && !propertyClass.getName().equals(ResourceAttributes.NAME)) { l = propertyClass.getDefinitions(); for (PropertyDefinition d : l) { AttributeDefinition def = (AttributeDefinition) d; if (def.isReplaceable()) { addVariable(def.getPropertyClass().getName() + ":" + def.getName(), def.getDescription(), buf, pageContext, bundle, locale, inputId); } } } } } catch (Exception e) { log.error("Failed to get user attribute definitions."); } } buf.append("</ul>"); buf.append("</div>"); buf.append("</div>"); return buf.toString(); }
From source file:com.adito.input.tags.VariablesTag.java
/** * Method to generate the Replacement Variable Chooser Fragment. * /*from w w w. j av a 2 s. c om*/ * @param titleKey * @param pageContext * @param bundle * @param locale * @param inputId * @param variables * @param includeSession * @param includeUserAttributes * @param includeRequest * @return String * @throws JspException */ public static String generateReplacementVariableChooserFragment(String titleKey, PageContext pageContext, String bundle, String locale, String inputId, String variables, boolean includeSession, boolean includeUserAttributes, boolean includeRequest) throws JspException { StringBuffer buf = new StringBuffer(); String title = null; if (titleKey != null) { title = TagUtils.getInstance().message(pageContext, bundle, locale, titleKey, new String[] {}); } if (title == null) { title = TagUtils.getInstance().message(pageContext, bundle, locale, "replacementVariablesChooser.title", new String[] {}); if (title == null) { title = "Replacement Variables"; } } buf.append("<div class=\"component_replacementVariablesToggle\">"); // buf.append("<input type=\"button\" // onclick=\"toggleAndPositionBelow(document.getElementById('replacementVariablesChooser"); // buf.append(inputId); // buf.append("'), document.getElementById('"); // buf.append(inputId); // buf.append("'))\" "); // buf.append("value=\"${}\"/>"); buf.append("<img onclick=\"togglePopupBelowLeft(document.getElementById('replacementVariablesChooser"); buf.append(inputId); buf.append("'), document.getElementById('"); buf.append(inputId); buf.append("'))\" "); buf.append("src=\""); buf.append(CoreUtil.getThemePath(pageContext.getSession())); buf.append("/images/variables.gif\"/>"); buf.append("</div>"); buf.append("<div id=\"replacementVariablesChooser"); buf.append(inputId); buf.append("\" style=\"position:absolute;display: none;overflow:visible;top:4px;left:4px;z-index:900;\">"); buf.append("<div class=\"replacementVariablesMain\">"); buf.append("<div class=\"replacementVariablesTitleBar\">"); buf.append("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"); buf.append("<tr><td class=\"title\">"); buf.append(title); buf.append("</td><td class=\"close\"><img src=\""); buf.append(CoreUtil.getThemePath(pageContext.getSession())); buf.append("/images/actions/erase.gif\" "); buf.append("onclick=\"document.getElementById('"); buf.append(inputId); buf.append("').value = ''\"/><img src=\""); buf.append(CoreUtil.getThemePath(pageContext.getSession())); buf.append("/images/actions/closeReplacementVariables.gif\" "); buf.append("onclick=\"togglePopup(document.getElementById('replacementVariablesChooser"); buf.append(inputId); buf.append("'))\"/>"); buf.append("</td></tr></table></div><div class=\"replacementVariablesContent\">"); buf.append("<ul>"); if (variables != null) { StringTokenizer t = new StringTokenizer(variables, ","); while (t.hasMoreTokens()) { String n = t.nextToken(); addVariable(n, n, buf, pageContext, bundle, locale, inputId); } } if (includeSession) { addVariable("session:username", null, buf, pageContext, bundle, locale, inputId); addVariable("session:password", null, buf, pageContext, bundle, locale, inputId); addVariable("session:email", null, buf, pageContext, bundle, locale, inputId); addVariable("session:fullname", null, buf, pageContext, bundle, locale, inputId); addVariable("session:clientProxyURL", null, buf, pageContext, bundle, locale, inputId); addVariable("session:clientReverseProxyURL", null, buf, pageContext, bundle, locale, inputId); } if (includeRequest) { addVariable("request:serverName", null, buf, pageContext, bundle, locale, inputId); addVariable("request:serverPort", null, buf, pageContext, bundle, locale, inputId); addVariable("request:userAgent", null, buf, pageContext, bundle, locale, inputId); } if (includeUserAttributes) { Collection<PropertyDefinition> l; try { for (PropertyClass propertyClass : PropertyClassManager.getInstance().getPropertyClasses()) { if (propertyClass instanceof AttributesPropertyClass && !propertyClass.getName().equals(ResourceAttributes.NAME)) { l = propertyClass.getDefinitions(); for (PropertyDefinition d : l) { AttributeDefinition def = (AttributeDefinition) d; if (def.isReplaceable()) { addVariable(def.getPropertyClass().getName() + ":" + def.getName(), def.getDescription(), buf, pageContext, bundle, locale, inputId); } } } } } catch (Exception e) { log.error("Failed to get user attribute definitions."); } } buf.append("</ul>"); buf.append("</div>"); buf.append("</div>"); return buf.toString(); }
From source file:com.amalto.core.save.context.PartialUpdateActionCreator.java
private static void resetPath(String currentPath, Stack<String> path) { StringTokenizer pathIterator = new StringTokenizer(currentPath, "/"); //$NON-NLS-1$ path.clear();/*from w w w . j a va2s . c om*/ while (pathIterator.hasMoreTokens()) { path.add(pathIterator.nextToken()); } }
From source file:com.bitdubai.fermat_api.layer.all_definition.crypto.asymmetric.util.PublicKeyReaderUtil.java
/** * <p>Extracts from the OpenSSH public key format the base64 encoded SSH * public key.</p>/*from w w w.j a va 2s . com*/ * <p>An example of such a definition is:<br/> * <code>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA1on8gxCGJJWSRT4uOrR130....</code> * </p> * * @param _key text of the public key defined in the OpenSSH format * @return base64 encoded public-key data * @throws PublicKeyParseException if the OpenSSH public key string is * corrupt * @see PublicKeyParseException.ErrorCode#CORRUPT_OPENSSH_PUBLIC_KEY_STRING * @see <a href="http://www.openssh.org">OpenSSH</a> */ public static String extractOpenSSHBase64(final String _key) throws PublicKeyParseException { final String base64; try { final StringTokenizer st = new StringTokenizer(_key); st.nextToken(); base64 = st.nextToken(); } catch (final NoSuchElementException e) { throw new PublicKeyParseException(PublicKeyParseException.ErrorCode.CORRUPT_OPENSSH_PUBLIC_KEY_STRING); } return base64; }
From source file:com.netspective.sparx.panel.editor.ReportPanelEditorContentElement.java
public static String getPkValueFromState(PanelEditorState state) { if (state.getActiveElementInfo() != null) { StringTokenizer st = new StringTokenizer(state.getActiveElementInfo()); if (st.hasMoreTokens()) return st.nextToken(); }/* w w w.j a v a2 s . c om*/ return null; }