java.lang.String#substring ( )源码实例Demo

下面列出了java.lang.String#substring ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8-source   文件: Messages.java
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;
}
 
源代码2 项目: openjdk-8   文件: Messages.java
/**
 * 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;

}
 
源代码3 项目: TencentKona-8   文件: Messages.java
/**
 * 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;

}
 
源代码4 项目: openjdk-jdk9   文件: Messages.java
/**
 * 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;

}
 
源代码5 项目: jdk8u60   文件: Messages.java
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;
}
 
源代码6 项目: openjdk-jdk8u   文件: Messages.java
/**
 * 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;

}
 
源代码7 项目: openjdk-jdk9   文件: Messages.java
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;
}
 
源代码8 项目: hottub   文件: Messages.java
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;
}
 
源代码9 项目: openjdk-8   文件: Messages.java
/**
 * 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;

}
 
源代码10 项目: openjdk-8   文件: Messages.java
/**
 * 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);
    }

}
 
源代码11 项目: TencentKona-8   文件: FileLocator.java
/**
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that
 * can be used to read the requested file, but the name of the file is
 * determined using information from the current locale and the supplied
 * file name (which is treated as a "base" name, and is supplemented with
 * country and language related suffixes, obtained from the current
 * locale).  The CLASSPATH is used to locate the file.
 *
 * @param fileName The name of the file to locate.  The file name
 * may be qualified with a partial path name, using '/' as the separator
 * character or using separator characters appropriate for the host file
 * system, in which case each directory or zip file in the CLASSPATH will
 * be used as a base for finding the fully-qualified file.
 * Here is an example of how the supplied fileName is used as a base
 * for locating a locale-specific file:
 *
 * <pre>
 *     Supplied fileName: a/b/c/x.y,  current locale: US English
 *
 *                     Look first for: a/b/c/x_en_US.y
 *     (if that fails) Look next for:  a/b/c/x_en.y
 *     (if that fails) Look last for:  a/b/c/x.y
 *
 *     All elements of the class path are searched for each name,
 *     before the next possible name is tried.
 * </pre>
 *
 * @exception java.io.FileNotFoundException The requested class file
 * could not be found.
 * @exception java.io.IOException The requested class file
 * could not be opened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath (
    String fileName) throws FileNotFoundException, IOException {

    String localeSuffix = "_" + Locale.getDefault ().toString ();
    int lastSlash = fileName.lastIndexOf ('/');
    int lastDot   = fileName.lastIndexOf ('.');
    String fnFront, fnEnd;
    DataInputStream result = null;
    boolean lastAttempt = false;

    if ((lastDot > 0) && (lastDot > lastSlash)) {
        fnFront = fileName.substring (0, lastDot);
        fnEnd   = fileName.substring (lastDot);
    } else {
        fnFront = fileName;
        fnEnd   = "";
    }

    while (true) {
        if (lastAttempt)
            result = locateFileInClassPath (fileName);
        else try {
            result = locateFileInClassPath (fnFront + localeSuffix + fnEnd);
        } catch (Exception e) { /* ignore */ }
        if ((result != null) || lastAttempt)
            break;
        int lastUnderbar = localeSuffix.lastIndexOf ('_');
        if (lastUnderbar > 0)
            localeSuffix = localeSuffix.substring (0, lastUnderbar);
        else
            lastAttempt = true;
    }
    return result;

}
 
源代码12 项目: jdk8u60   文件: Messages.java
/**
 * 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);
    }

}
 
源代码13 项目: hottub   文件: FileLocator.java
/**
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that
 * can be used to read the requested file, but the name of the file is
 * determined using information from the current locale and the supplied
 * file name (which is treated as a "base" name, and is supplemented with
 * country and language related suffixes, obtained from the current
 * locale).  The CLASSPATH is used to locate the file.
 *
 * @param fileName The name of the file to locate.  The file name
 * may be qualified with a partial path name, using '/' as the separator
 * character or using separator characters appropriate for the host file
 * system, in which case each directory or zip file in the CLASSPATH will
 * be used as a base for finding the fully-qualified file.
 * Here is an example of how the supplied fileName is used as a base
 * for locating a locale-specific file:
 *
 * <pre>
 *     Supplied fileName: a/b/c/x.y,  current locale: US English
 *
 *                     Look first for: a/b/c/x_en_US.y
 *     (if that fails) Look next for:  a/b/c/x_en.y
 *     (if that fails) Look last for:  a/b/c/x.y
 *
 *     All elements of the class path are searched for each name,
 *     before the next possible name is tried.
 * </pre>
 *
 * @exception java.io.FileNotFoundException The requested class file
 * could not be found.
 * @exception java.io.IOException The requested class file
 * could not be opened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath (
    String fileName) throws FileNotFoundException, IOException {

    String localeSuffix = "_" + Locale.getDefault ().toString ();
    int lastSlash = fileName.lastIndexOf ('/');
    int lastDot   = fileName.lastIndexOf ('.');
    String fnFront, fnEnd;
    DataInputStream result = null;
    boolean lastAttempt = false;

    if ((lastDot > 0) && (lastDot > lastSlash)) {
        fnFront = fileName.substring (0, lastDot);
        fnEnd   = fileName.substring (lastDot);
    } else {
        fnFront = fileName;
        fnEnd   = "";
    }

    while (true) {
        if (lastAttempt)
            result = locateFileInClassPath (fileName);
        else try {
            result = locateFileInClassPath (fnFront + localeSuffix + fnEnd);
        } catch (Exception e) { /* ignore */ }
        if ((result != null) || lastAttempt)
            break;
        int lastUnderbar = localeSuffix.lastIndexOf ('_');
        if (lastUnderbar > 0)
            localeSuffix = localeSuffix.substring (0, lastUnderbar);
        else
            lastAttempt = true;
    }
    return result;

}
 
源代码14 项目: jdk8u60   文件: FileLocator.java
/**
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that
 * can be used to read the requested file, but the name of the file is
 * determined using information from the current locale and the supplied
 * file name (which is treated as a "base" name, and is supplemented with
 * country and language related suffixes, obtained from the current
 * locale).  The CLASSPATH is used to locate the file.
 *
 * @param fileName The name of the file to locate.  The file name
 * may be qualified with a partial path name, using '/' as the separator
 * character or using separator characters appropriate for the host file
 * system, in which case each directory or zip file in the CLASSPATH will
 * be used as a base for finding the fully-qualified file.
 * Here is an example of how the supplied fileName is used as a base
 * for locating a locale-specific file:
 *
 * <pre>
 *     Supplied fileName: a/b/c/x.y,  current locale: US English
 *
 *                     Look first for: a/b/c/x_en_US.y
 *     (if that fails) Look next for:  a/b/c/x_en.y
 *     (if that fails) Look last for:  a/b/c/x.y
 *
 *     All elements of the class path are searched for each name,
 *     before the next possible name is tried.
 * </pre>
 *
 * @exception java.io.FileNotFoundException The requested class file
 * could not be found.
 * @exception java.io.IOException The requested class file
 * could not be opened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath (
    String fileName) throws FileNotFoundException, IOException {

    String localeSuffix = "_" + Locale.getDefault ().toString ();
    int lastSlash = fileName.lastIndexOf ('/');
    int lastDot   = fileName.lastIndexOf ('.');
    String fnFront, fnEnd;
    DataInputStream result = null;
    boolean lastAttempt = false;

    if ((lastDot > 0) && (lastDot > lastSlash)) {
        fnFront = fileName.substring (0, lastDot);
        fnEnd   = fileName.substring (lastDot);
    } else {
        fnFront = fileName;
        fnEnd   = "";
    }

    while (true) {
        if (lastAttempt)
            result = locateFileInClassPath (fileName);
        else try {
            result = locateFileInClassPath (fnFront + localeSuffix + fnEnd);
        } catch (Exception e) { /* ignore */ }
        if ((result != null) || lastAttempt)
            break;
        int lastUnderbar = localeSuffix.lastIndexOf ('_');
        if (lastUnderbar > 0)
            localeSuffix = localeSuffix.substring (0, lastUnderbar);
        else
            lastAttempt = true;
    }
    return result;

}
 
源代码15 项目: openjdk-jdk9   文件: Messages.java
/**
 * 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);
    }

}
 
源代码16 项目: openjdk-jdk8u-backup   文件: FileLocator.java
/**
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that
 * can be used to read the requested file, but the name of the file is
 * determined using information from the current locale and the supplied
 * file name (which is treated as a "base" name, and is supplemented with
 * country and language related suffixes, obtained from the current
 * locale).  The CLASSPATH is used to locate the file.
 *
 * @param fileName The name of the file to locate.  The file name
 * may be qualified with a partial path name, using '/' as the separator
 * character or using separator characters appropriate for the host file
 * system, in which case each directory or zip file in the CLASSPATH will
 * be used as a base for finding the fully-qualified file.
 * Here is an example of how the supplied fileName is used as a base
 * for locating a locale-specific file:
 *
 * <pre>
 *     Supplied fileName: a/b/c/x.y,  current locale: US English
 *
 *                     Look first for: a/b/c/x_en_US.y
 *     (if that fails) Look next for:  a/b/c/x_en.y
 *     (if that fails) Look last for:  a/b/c/x.y
 *
 *     All elements of the class path are searched for each name,
 *     before the next possible name is tried.
 * </pre>
 *
 * @exception java.io.FileNotFoundException The requested class file
 * could not be found.
 * @exception java.io.IOException The requested class file
 * could not be opened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath (
    String fileName) throws FileNotFoundException, IOException {

    String localeSuffix = "_" + Locale.getDefault ().toString ();
    int lastSlash = fileName.lastIndexOf ('/');
    int lastDot   = fileName.lastIndexOf ('.');
    String fnFront, fnEnd;
    DataInputStream result = null;
    boolean lastAttempt = false;

    if ((lastDot > 0) && (lastDot > lastSlash)) {
        fnFront = fileName.substring (0, lastDot);
        fnEnd   = fileName.substring (lastDot);
    } else {
        fnFront = fileName;
        fnEnd   = "";
    }

    while (true) {
        if (lastAttempt)
            result = locateFileInClassPath (fileName);
        else try {
            result = locateFileInClassPath (fnFront + localeSuffix + fnEnd);
        } catch (Exception e) { /* ignore */ }
        if ((result != null) || lastAttempt)
            break;
        int lastUnderbar = localeSuffix.lastIndexOf ('_');
        if (lastUnderbar > 0)
            localeSuffix = localeSuffix.substring (0, lastUnderbar);
        else
            lastAttempt = true;
    }
    return result;

}
 
源代码17 项目: openjdk-jdk8u   文件: FileLocator.java
/**
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that
 * can be used to read the requested file, but the name of the file is
 * determined using information from the current locale and the supplied
 * file name (which is treated as a "base" name, and is supplemented with
 * country and language related suffixes, obtained from the current
 * locale).  The CLASSPATH is used to locate the file.
 *
 * @param fileName The name of the file to locate.  The file name
 * may be qualified with a partial path name, using '/' as the separator
 * character or using separator characters appropriate for the host file
 * system, in which case each directory or zip file in the CLASSPATH will
 * be used as a base for finding the fully-qualified file.
 * Here is an example of how the supplied fileName is used as a base
 * for locating a locale-specific file:
 *
 * <pre>
 *     Supplied fileName: a/b/c/x.y,  current locale: US English
 *
 *                     Look first for: a/b/c/x_en_US.y
 *     (if that fails) Look next for:  a/b/c/x_en.y
 *     (if that fails) Look last for:  a/b/c/x.y
 *
 *     All elements of the class path are searched for each name,
 *     before the next possible name is tried.
 * </pre>
 *
 * @exception java.io.FileNotFoundException The requested class file
 * could not be found.
 * @exception java.io.IOException The requested class file
 * could not be opened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath (
    String fileName) throws FileNotFoundException, IOException {

    String localeSuffix = "_" + Locale.getDefault ().toString ();
    int lastSlash = fileName.lastIndexOf ('/');
    int lastDot   = fileName.lastIndexOf ('.');
    String fnFront, fnEnd;
    DataInputStream result = null;
    boolean lastAttempt = false;

    if ((lastDot > 0) && (lastDot > lastSlash)) {
        fnFront = fileName.substring (0, lastDot);
        fnEnd   = fileName.substring (lastDot);
    } else {
        fnFront = fileName;
        fnEnd   = "";
    }

    while (true) {
        if (lastAttempt)
            result = locateFileInClassPath (fileName);
        else try {
            result = locateFileInClassPath (fnFront + localeSuffix + fnEnd);
        } catch (Exception e) { /* ignore */ }
        if ((result != null) || lastAttempt)
            break;
        int lastUnderbar = localeSuffix.lastIndexOf ('_');
        if (lastUnderbar > 0)
            localeSuffix = localeSuffix.substring (0, lastUnderbar);
        else
            lastAttempt = true;
    }
    return result;

}
 
源代码18 项目: openjdk-jdk8u-backup   文件: Messages.java
/**
 * 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);
    }

}
 
源代码19 项目: JarBundler   文件: JarBundler.java
private String bundlePath(File bundleFile) {
	String rootPath = bundleDir.getAbsolutePath();
	String thisPath = bundleFile.getAbsolutePath();

	return thisPath.substring(rootPath.length());
}
 
源代码20 项目: carbon-apimgt   文件: APITemplateBuilderImpl.java
@Override
public String getConfigStringForDefaultAPITemplate(String defaultVersion) throws APITemplateException {
    StringWriter writer = new StringWriter();

    try {
        VelocityEngine velocityengine = new VelocityEngine();
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    CommonsLogLogChute.class.getName());
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }

        velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
        initVelocityEngine(velocityengine);

        ConfigContext configcontext = new APIConfigContext(this.api);
        configcontext = new TransportConfigContext(configcontext, api);
        configcontext = new ResourceConfigContext(configcontext, api);
        configcontext = new TemplateUtilContext(configcontext);

        VelocityContext context = configcontext.getContext();
        context.put("defaultVersion", defaultVersion);
        String fwdApiContext = this.api.getContext();
        if (fwdApiContext != null && fwdApiContext.charAt(0) == '/') {
            fwdApiContext = fwdApiContext.substring(1);
        }
        context.put("fwdApiContext", fwdApiContext);

        // for default version, we remove the {version} param from the apiContext
        String apiContext = this.api.getContextTemplate();
        if(apiContext.contains("{version}")){
            apiContext = apiContext.replace("/{version}","");
            apiContext = apiContext.replace("{version}","");
        }

        context.put("apiContext", apiContext);

        Template t = velocityengine.getTemplate(this.getDefaultAPITemplatePath());

        t.merge(context, writer);
    } catch (Exception e) {
        log.error("Velocity Error", e);
        throw new APITemplateException("Velocity Error", e);
    }
    return writer.toString();
}