Java Code Examples for java.lang.String#indexOf()
The following examples show how to use
java.lang.String#indexOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Messages.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static String substituteString(String orig, int paramNum, String subst){ String result = orig; String paramSubst = "%"+ paramNum; int len = paramSubst.length(); int index = result.indexOf (paramSubst); String ending = ""; if (index >= 0) { if ((index+len) < result.length ()) ending = result.substring (index+len); result = result.substring (0, index) + subst + ending; } else result += " " + subst; return result; }
Example 2
Source File: Messages.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of two arguments, supplied by the "parm1" and "parm2" parameters. * If the message text does not contain the meta characters "%1" and * "%2" that indicate where to place the arguments, the passed arguments * are appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm1, String parm2) { if (loadNeeded) loadDefaultProperties (); String result = m.getProperty (msgkey, msgkey); String ending = ""; int i = result.indexOf ("%1"); if (i >= 0) { if ((i+2) < result.length ()) ending = result.substring (i+2); result = result.substring (0, i) + parm1 + ending; } else result += " " + parm1; i = result.indexOf ("%2"); if (i >= 0) { ending = ""; if ((i+2) < result.length ()) ending = result.substring (i+2); result = result.substring (0, i) + parm2 + ending; } else result += " " + parm2; return result; }
Example 3
Source File: Messages.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of a single argument, supplied by the "parm" parameter. * If the message text does not contain the meta characters "%1" * that indicate where to place the argument, the passed argument * is appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm) { if (loadNeeded) loadDefaultProperties (); String msgtext = m.getProperty (msgkey, msgkey); int i = msgtext.indexOf ("%1"); if (i >= 0) { String ending = ""; if ((i+2) < msgtext.length ()) ending = msgtext.substring (i+2); return msgtext.substring (0, i) + parm + ending; } else msgtext += " " + parm; return msgtext; }
Example 4
Source File: Messages.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of two arguments, supplied by the "parm1" and "parm2" parameters. * If the message text does not contain the meta characters "%1" and * "%2" that indicate where to place the arguments, the passed arguments * are appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm1, String parm2) { if (loadNeeded) loadDefaultProperties (); String result = m.getProperty (msgkey, msgkey); String ending = ""; int i = result.indexOf ("%1"); if (i >= 0) { if ((i+2) < result.length ()) ending = result.substring (i+2); result = result.substring (0, i) + parm1 + ending; } else result += " " + parm1; i = result.indexOf ("%2"); if (i >= 0) { ending = ""; if ((i+2) < result.length ()) ending = result.substring (i+2); result = result.substring (0, i) + parm2 + ending; } else result += " " + parm2; return result; }
Example 5
Source File: Messages.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of a single argument, supplied by the "parm" parameter. * If the message text does not contain the meta characters "%1" * that indicate where to place the argument, the passed argument * is appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm) { if (loadNeeded) loadDefaultProperties (); String msgtext = m.getProperty (msgkey, msgkey); int i = msgtext.indexOf ("%1"); if (i >= 0) { String ending = ""; if ((i+2) < msgtext.length ()) ending = msgtext.substring (i+2); return msgtext.substring (0, i) + parm + ending; } else msgtext += " " + parm; return msgtext; }
Example 6
Source File: Messages.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static String substituteString(String orig, int paramNum, String subst){ String result = orig; String paramSubst = "%"+ paramNum; int len = paramSubst.length(); int index = result.indexOf (paramSubst); String ending = ""; if (index >= 0) { if ((index+len) < result.length ()) ending = result.substring (index+len); result = result.substring (0, index) + subst + ending; } else result += " " + subst; return result; }
Example 7
Source File: Messages.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of a single argument, supplied by the "parm" parameter. * If the message text does not contain the meta characters "%1" * that indicate where to place the argument, the passed argument * is appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm) { if (loadNeeded) loadDefaultProperties (); String msgtext = m.getProperty (msgkey, msgkey); int i = msgtext.indexOf ("%1"); if (i >= 0) { String ending = ""; if ((i+2) < msgtext.length ()) ending = msgtext.substring (i+2); return msgtext.substring (0, i) + parm + ending; } else msgtext += " " + parm; return msgtext; }
Example 8
Source File: Messages.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private static String substituteString(String orig, int paramNum, String subst){ String result = orig; String paramSubst = "%"+ paramNum; int len = paramSubst.length(); int index = result.indexOf (paramSubst); String ending = ""; if (index >= 0) { if ((index+len) < result.length ()) ending = result.substring (index+len); result = result.substring (0, index) + subst + ending; } else result += " " + subst; return result; }
Example 9
Source File: Messages.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of a single argument, supplied by the "parm" parameter. * If the message text does not contain the meta characters "%1" * that indicate where to place the argument, the passed argument * is appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm) { if (loadNeeded) loadDefaultProperties (); String msgtext = m.getProperty (msgkey, msgkey); int i = msgtext.indexOf ("%1"); if (i >= 0) { String ending = ""; if ((i+2) < msgtext.length ()) ending = msgtext.substring (i+2); return msgtext.substring (0, i) + parm + ending; } else msgtext += " " + parm; return msgtext; }
Example 10
Source File: Messages.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static String substituteString(String orig, int paramNum, String subst){ String result = orig; String paramSubst = "%"+ paramNum; int len = paramSubst.length(); int index = result.indexOf (paramSubst); String ending = ""; if (index >= 0) { if ((index+len) < result.length ()) ending = result.substring (index+len); result = result.substring (0, index) + subst + ending; } else result += " " + subst; return result; }
Example 11
Source File: Messages.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of a single argument, supplied by the "parm" parameter. * If the message text does not contain the meta characters "%1" * that indicate where to place the argument, the passed argument * is appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm) { if (loadNeeded) loadDefaultProperties (); String msgtext = m.getProperty (msgkey, msgkey); int i = msgtext.indexOf ("%1"); if (i >= 0) { String ending = ""; if ((i+2) < msgtext.length ()) ending = msgtext.substring (i+2); return msgtext.substring (0, i) + parm + ending; } else msgtext += " " + parm; return msgtext; }
Example 12
Source File: Messages.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of two arguments, supplied by the "parm1" and "parm2" parameters. * If the message text does not contain the meta characters "%1" and * "%2" that indicate where to place the arguments, the passed arguments * are appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm1, String parm2) { if (loadNeeded) loadDefaultProperties (); String result = m.getProperty (msgkey, msgkey); String ending = ""; int i = result.indexOf ("%1"); if (i >= 0) { if ((i+2) < result.length ()) ending = result.substring (i+2); result = result.substring (0, i) + parm1 + ending; } else result += " " + parm1; i = result.indexOf ("%2"); if (i >= 0) { ending = ""; if ((i+2) < result.length ()) ending = result.substring (i+2); result = result.substring (0, i) + parm2 + ending; } else result += " " + parm2; return result; }
Example 13
Source File: Messages.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Returns the message text corresponding to the passed msgkey * string. The message text is assumed to require the insertion * of a single argument, supplied by the "parm" parameter. * If the message text does not contain the meta characters "%1" * that indicate where to place the argument, the passed argument * is appended at the end of the message text. * <p> * If the msgkey cannot be found, its value is used as the * message text. */ public static final String msg (String msgkey, String parm) { if (loadNeeded) loadDefaultProperties (); String msgtext = m.getProperty (msgkey, msgkey); int i = msgtext.indexOf ("%1"); if (i >= 0) { String ending = ""; if ((i+2) < msgtext.length ()) ending = msgtext.substring (i+2); return msgtext.substring (0, i) + parm + ending; } else msgtext += " " + parm; return msgtext; }
Example 14
Source File: Messages.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * This method was introduced to fix defect #26964. For Java 1.0.2 * on Win NT, the escape sequence \u0020 was not being handled * correctly by the Java Properties class when it was the final * character of a line. Instead the trailing blank was dropped * and the next line was swallowed as a continuation. To work * around the problem, we introduced our own metasymbol to represent * a trailing blank. Hence: * * Performs substitution for any metasymbols in the message * templates. So far only %B is needed. This was introduced * to make it more convenient for .properties files to * contain message templates with leading or trailing blanks * (although %B may actually occur anywhere in a template). * Subsequently, checking for '\n' has also been added. Now, * wherever '\n' occurs in a message template, it is replaced * with the value of System.getProperty ("line.separator"). */ private static final void fixMessages (Properties p) { Enumeration keys = p.keys (); Enumeration elems = p.elements (); while (keys.hasMoreElements ()) { String key = (String) keys.nextElement (); String elem = (String) elems.nextElement (); int i = elem.indexOf (LTB); boolean changed = false; while (i != -1) { if (i == 0) elem = " " + elem.substring (2); else elem = elem.substring (0, i) + " " + elem.substring (i+2); changed = true; i = elem.indexOf (LTB); } int lsIncr = lineSeparator.length () - 1; for (i=0; i<elem.length (); i++) { if (elem.charAt (i) == NL) { elem = elem.substring (0, i) + lineSeparator + elem.substring (i+1); i += lsIncr; changed = true; } } if (changed) p.put (key, elem); } }
Example 15
Source File: Messages.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * This method was introduced to fix defect #26964. For Java 1.0.2 * on Win NT, the escape sequence \u0020 was not being handled * correctly by the Java Properties class when it was the final * character of a line. Instead the trailing blank was dropped * and the next line was swallowed as a continuation. To work * around the problem, we introduced our own metasymbol to represent * a trailing blank. Hence: * * Performs substitution for any metasymbols in the message * templates. So far only %B is needed. This was introduced * to make it more convenient for .properties files to * contain message templates with leading or trailing blanks * (although %B may actually occur anywhere in a template). * Subsequently, checking for '\n' has also been added. Now, * wherever '\n' occurs in a message template, it is replaced * with the value of System.getProperty ("line.separator"). */ private static final void fixMessages (Properties p) { Enumeration keys = p.keys (); Enumeration elems = p.elements (); while (keys.hasMoreElements ()) { String key = (String) keys.nextElement (); String elem = (String) elems.nextElement (); int i = elem.indexOf (LTB); boolean changed = false; while (i != -1) { if (i == 0) elem = " " + elem.substring (2); else elem = elem.substring (0, i) + " " + elem.substring (i+2); changed = true; i = elem.indexOf (LTB); } int lsIncr = lineSeparator.length () - 1; for (i=0; i<elem.length (); i++) { if (elem.charAt (i) == NL) { elem = elem.substring (0, i) + lineSeparator + elem.substring (i+1); i += lsIncr; changed = true; } } if (changed) p.put (key, elem); } }
Example 16
Source File: Messages.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * This method was introduced to fix defect #26964. For Java 1.0.2 * on Win NT, the escape sequence \u0020 was not being handled * correctly by the Java Properties class when it was the final * character of a line. Instead the trailing blank was dropped * and the next line was swallowed as a continuation. To work * around the problem, we introduced our own metasymbol to represent * a trailing blank. Hence: * * Performs substitution for any metasymbols in the message * templates. So far only %B is needed. This was introduced * to make it more convenient for .properties files to * contain message templates with leading or trailing blanks * (although %B may actually occur anywhere in a template). * Subsequently, checking for '\n' has also been added. Now, * wherever '\n' occurs in a message template, it is replaced * with the value of System.getProperty ("line.separator"). */ private static final void fixMessages (Properties p) { Enumeration keys = p.keys (); Enumeration elems = p.elements (); while (keys.hasMoreElements ()) { String key = (String) keys.nextElement (); String elem = (String) elems.nextElement (); int i = elem.indexOf (LTB); boolean changed = false; while (i != -1) { if (i == 0) elem = " " + elem.substring (2); else elem = elem.substring (0, i) + " " + elem.substring (i+2); changed = true; i = elem.indexOf (LTB); } int lsIncr = lineSeparator.length () - 1; for (i=0; i<elem.length (); i++) { if (elem.charAt (i) == NL) { elem = elem.substring (0, i) + lineSeparator + elem.substring (i+1); i += lsIncr; changed = true; } } if (changed) p.put (key, elem); } }
Example 17
Source File: Messages.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * This method was introduced to fix defect #26964. For Java 1.0.2 * on Win NT, the escape sequence \u0020 was not being handled * correctly by the Java Properties class when it was the final * character of a line. Instead the trailing blank was dropped * and the next line was swallowed as a continuation. To work * around the problem, we introduced our own metasymbol to represent * a trailing blank. Hence: * * Performs substitution for any metasymbols in the message * templates. So far only %B is needed. This was introduced * to make it more convenient for .properties files to * contain message templates with leading or trailing blanks * (although %B may actually occur anywhere in a template). * Subsequently, checking for '\n' has also been added. Now, * wherever '\n' occurs in a message template, it is replaced * with the value of System.getProperty ("line.separator"). */ private static final void fixMessages (Properties p) { Enumeration keys = p.keys (); Enumeration elems = p.elements (); while (keys.hasMoreElements ()) { String key = (String) keys.nextElement (); String elem = (String) elems.nextElement (); int i = elem.indexOf (LTB); boolean changed = false; while (i != -1) { if (i == 0) elem = " " + elem.substring (2); else elem = elem.substring (0, i) + " " + elem.substring (i+2); changed = true; i = elem.indexOf (LTB); } int lsIncr = lineSeparator.length () - 1; for (i=0; i<elem.length (); i++) { if (elem.charAt (i) == NL) { elem = elem.substring (0, i) + lineSeparator + elem.substring (i+1); i += lsIncr; changed = true; } } if (changed) p.put (key, elem); } }
Example 18
Source File: Messages.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * This method was introduced to fix defect #26964. For Java 1.0.2 * on Win NT, the escape sequence \u0020 was not being handled * correctly by the Java Properties class when it was the final * character of a line. Instead the trailing blank was dropped * and the next line was swallowed as a continuation. To work * around the problem, we introduced our own metasymbol to represent * a trailing blank. Hence: * * Performs substitution for any metasymbols in the message * templates. So far only %B is needed. This was introduced * to make it more convenient for .properties files to * contain message templates with leading or trailing blanks * (although %B may actually occur anywhere in a template). * Subsequently, checking for '\n' has also been added. Now, * wherever '\n' occurs in a message template, it is replaced * with the value of System.getProperty ("line.separator"). */ private static final void fixMessages (Properties p) { Enumeration keys = p.keys (); Enumeration elems = p.elements (); while (keys.hasMoreElements ()) { String key = (String) keys.nextElement (); String elem = (String) elems.nextElement (); int i = elem.indexOf (LTB); boolean changed = false; while (i != -1) { if (i == 0) elem = " " + elem.substring (2); else elem = elem.substring (0, i) + " " + elem.substring (i+2); changed = true; i = elem.indexOf (LTB); } int lsIncr = lineSeparator.length () - 1; for (i=0; i<elem.length (); i++) { if (elem.charAt (i) == NL) { elem = elem.substring (0, i) + lineSeparator + elem.substring (i+1); i += lsIncr; changed = true; } } if (changed) p.put (key, elem); } }
Example 19
Source File: Messages.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * This method was introduced to fix defect #26964. For Java 1.0.2 * on Win NT, the escape sequence \u0020 was not being handled * correctly by the Java Properties class when it was the final * character of a line. Instead the trailing blank was dropped * and the next line was swallowed as a continuation. To work * around the problem, we introduced our own metasymbol to represent * a trailing blank. Hence: * * Performs substitution for any metasymbols in the message * templates. So far only %B is needed. This was introduced * to make it more convenient for .properties files to * contain message templates with leading or trailing blanks * (although %B may actually occur anywhere in a template). * Subsequently, checking for '\n' has also been added. Now, * wherever '\n' occurs in a message template, it is replaced * with the value of System.getProperty ("line.separator"). */ private static final void fixMessages (Properties p) { Enumeration keys = p.keys (); Enumeration elems = p.elements (); while (keys.hasMoreElements ()) { String key = (String) keys.nextElement (); String elem = (String) elems.nextElement (); int i = elem.indexOf (LTB); boolean changed = false; while (i != -1) { if (i == 0) elem = " " + elem.substring (2); else elem = elem.substring (0, i) + " " + elem.substring (i+2); changed = true; i = elem.indexOf (LTB); } int lsIncr = lineSeparator.length () - 1; for (i=0; i<elem.length (); i++) { if (elem.charAt (i) == NL) { elem = elem.substring (0, i) + lineSeparator + elem.substring (i+1); i += lsIncr; changed = true; } } if (changed) p.put (key, elem); } }
Example 20
Source File: UserManagerAction.java From wandora with GNU General Public License v3.0 | 4 votes |
@Override protected HashMap<String, Object> getTemplateContext(Template template, HttpServletRequest req, HttpMethod method, String action, User user) throws ActionException { String editAction=req.getParameter("editaction"); if(editAction==null || editAction.length()==0) editAction="userlist"; HashMap<String,Object> params=super.getTemplateContext(template, req, method, action, user); String userName=req.getParameter("user"); if(userName!=null) userName=userName.trim(); if(userName!=null && userName.length()==0) userName=null; User userObject=null; String view="userlist"; String error=null; try{ if(editAction.equals("userlist")){ // no side effects, do nothing } else if(editAction.equals("viewuser")){ view="user"; // just check that the user is valid if(userName!=null) userObject=userStore.getUser(userName); } else if(editAction.equals("edituser") || editAction.equals("edituserlist")){ view="user"; if(editAction.equals("edituserlist")) view="userlist"; if(userName!=null) { userObject=userStore.getUser(userName); if(userObject!=null){ Enumeration<String> paramNames=req.getParameterNames(); while(paramNames.hasMoreElements()){ String key=paramNames.nextElement(); String[] values=req.getParameterValues(key); for(String value : values){ value=value.trim(); if(key.equals("setoption")){ int ind=value.indexOf("="); if(ind<0) userObject.setOption(value, ""); else { String k=value.substring(0,ind); String v=value.substring(ind+1); userObject.setOption(k,v); } } else if(key.equals("removeoption")){ userObject.removeOption(value); } else if(key.equals("addrole")){ userObject.addRole(value); } else if(key.equals("removerole")){ userObject.removeRole(value); } } } if(!userObject.saveUser()) error="NOEDIT"; } } } else if(editAction.equals("deleteuser")){ if(userName!=null) { if(!userStore.deleteUser(userName)) error="NODELETE"; } } else if(editAction.equals("newuser")){ view="user"; if(userName!=null) { userObject=userStore.newUser(userName); if(userObject==null) error="NONEW"; } } else return null; if(view.equals("user") && userObject==null) { if(error==null) error="INVALIDUSER"; view="userlist"; } if(view.equals("userlist")){ params.put("allUsers",userStore.getAllUsers()); } else { params.put("user",userObject); } }catch(UserStoreException use){ if(error==null) error="USERSTORE"; } params.put("editView",view); params.put("error",error); return params; }