Example usage for java.lang String replaceFirst

List of usage examples for java.lang String replaceFirst

Introduction

In this page you can find the example usage for java.lang String replaceFirst.

Prototype

public String replaceFirst(String regex, String replacement) 

Source Link

Document

Replaces the first substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:info.magnolia.cms.core.Path.java

public static String getNodePath(String path) {
    if (path.startsWith("/")) { //$NON-NLS-1$
        return path.replaceFirst("/", StringUtils.EMPTY); //$NON-NLS-1$
    }//from   w  w w  .j a  va  2  s  .co m
    return path;
}

From source file:com.adguard.compiler.Main.java

private static String getParamValue(String[] args, String paramName, String defaultValue) {
    if (args == null) {
        return defaultValue;
    }//from   w  w w .j a v  a2  s  . co  m
    for (String arg : args) {
        if (arg.startsWith(paramName)) {
            return arg.replaceFirst(paramName + "=", "");
        }
    }

    return defaultValue;
}

From source file:co.mafiagame.common.utils.MessageHolder.java

public static String get(String key, Lang lang, String... args) {
    try {/*from   www.j  a va2 s .c  o m*/
        String value;
        if (lang == Lang.FA)
            value = propertiesFa.getProperty(key);
        else
            value = properties.getProperty(key);
        if (args != null)
            for (String arg : args) {
                value = value.replaceFirst("%", arg);
            }
        return value;
    } catch (NullPointerException e) {
        logger.error("message with key {} not found", key);
        return key + Arrays.toString(args);
    }
}

From source file:com.savoirfairelinux.jmeter.openstack.test.AbstractOpenstackSamplerTest.java

@BeforeClass
public static void prepare() throws Exception {
    // load configuration
    configuration = new Properties();
    InputStream inputStream = AbstractOpenstackSamplerTest.class.getClassLoader()
            .getResourceAsStream("configuration.properties");

    if (inputStream != null)
        configuration.load(inputStream);

    // load arguments
    arguments = new Arguments();
    Properties argumentsProps = new Properties();
    inputStream = AbstractOpenstackSamplerTest.class.getClassLoader()
            .getResourceAsStream("arguments.properties");
    if (inputStream != null)
        argumentsProps.load(inputStream);
    for (Object key : argumentsProps.keySet())
        arguments.addArgument((String) key, argumentsProps.getProperty((String) key));

    // setup JMeter
    JMeterUtils.loadJMeterProperties("");

    // handle user defined global configuration
    for (Object key : configuration.keySet()) {
        String keyStr = (String) key;
        // set JVM properties
        if (keyStr.startsWith("jvm."))
            System.setProperty(keyStr.replaceFirst("^jvm\\.", ""), configuration.getProperty(keyStr));
        // set JMeter properties
        else if (keyStr.startsWith("jmeter."))
            JMeterUtils.setProperty(keyStr.replaceFirst("^jmeter\\.", ""), configuration.getProperty(keyStr));
    }/*  w w w  .j a  va2 s .  c  o m*/

    // disable stdout before the logging is correctly setup
    CustomStdOut customStdOut = new CustomStdOut(System.out);
    customStdOut.setEnabled(false);
    System.setOut(customStdOut);

    // initialize logging and locale
    JMeterUtils.initLogging();
    JMeterUtils.initLocale();

    // workaround to disable Jersey warning
    java.util.logging.Logger.getLogger("").setLevel(Level.SEVERE);

    // re-enable stdout
    customStdOut.setEnabled(true);
}

From source file:net.fenyo.mail4hotspot.service.Browser.java

private static String _encode(final String source_url, /*final*/ String target_url, final String prefix,
        final boolean url_encode) throws UnsupportedEncodingException {
    String base = source_url;
    base = base.replaceFirst("(?is)^([^:]*://[^/]*)/.*$", "$1");

    //      target_url = "toto";
    //      log.debug("");
    //      log.debug("ENCODE:");
    //      log.debug("source=" + source_url);
    //      log.debug("target=" + target_url);

    if (target_url.toLowerCase().startsWith("http:") || target_url.toLowerCase().startsWith("https:")
            || target_url.toLowerCase().startsWith("ftp:")) {
        // target_url est une URL absolue
        return prefix + urlEncoder(target_url, url_encode);
    }/*from w ww  .  j av  a  2  s. c  om*/

    if (target_url.startsWith("/")) {
        // target_url est une URL relative au site
        return prefix + urlEncoder(base + target_url, url_encode);
    }

    //  partir d'ici, target_url est une URL relative

    if (source_url.matches("(?is)[^:]*://[^/]*$"))
        return prefix + urlEncoder(source_url + "/" + target_url, url_encode);

    return prefix + urlEncoder(source_url.replaceFirst("(?is)^([^:]*://[^?]*/).*$", "$1") + "/" + target_url,
            url_encode);
}

From source file:Main.java

public static String getNodeAttributeFromXmlUrl(String xmlUrl, String nodeWeiZhi, String attributeName) {
    String result = "";
    try {/*from   ww w  .  j  a  v a2 s . c  o m*/
        xmlUrl = xmlUrl.trim();
        Element element = getRootNodeFromXmlUrl(xmlUrl);
        result = getNodeAttribute(element, nodeWeiZhi, attributeName);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result.replaceFirst(",", "");
}

From source file:Main.java

public static String getNodeAttributeFromXmlStr(String xmlStr, String nodeWeiZhi, String attributeName) {
    String result = "";
    try {/*www .  j  a  v a 2s. c o m*/
        xmlStr = xmlStr.trim();
        Element element = getRootNodeFromXmlStr(xmlStr);
        result = getNodeAttribute(element, nodeWeiZhi, attributeName);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result.replaceFirst(",", "");
}

From source file:com.mymita.vaadlets.JAXBUtils.java

private static final void marshal(final Writer aWriter, final Vaadlets vaadlets,
        final Resource theSchemaResource) {
    try {/*w w w.  j a  va2s.  c  o  m*/
        final JAXBContext jc = JAXBContext.newInstance(CONTEXTPATH);
        final Marshaller marshaller = jc.createMarshaller();
        if (theSchemaResource != null) {
            final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            schemaFactory.setResourceResolver(new ClasspathResourceResolver());
            final Schema schema = schemaFactory.newSchema(new StreamSource(theSchemaResource.getInputStream()));
            marshaller.setSchema(schema);
        }
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
                new com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper() {

                    @Override
                    public String getPreferredPrefix(final String namespaceUri, final String suggestion,
                            final boolean requirePrefix) {
                        final String subpackage = namespaceUri.replaceFirst("http://www.mymita.com/vaadlets/",
                                "");
                        if (subpackage.equals("1.0.0")) {
                            return "";
                        }
                        return Iterables.getFirst(newArrayList(Splitter.on("/").split(subpackage).iterator()),
                                "");
                    }
                });
        marshaller.marshal(
                new JAXBElement<Vaadlets>(new QName("http://www.mymita.com/vaadlets/1.0.0", "vaadlets", ""),
                        Vaadlets.class, vaadlets),
                aWriter);
    } catch (final JAXBException | SAXException | FactoryConfigurationError | IOException e) {
        throw new RuntimeException("Can't marschal", e);
    }
}

From source file:org.imsglobal.lti.LTIUtil.java

/**
* Converts a float value to a String value
*
* @param fValue to be converted/*from   w  w  w. j a v a2s  . c o m*/
*
* @return converted value
*/
public static String floatToString(float fValue) {

    String value = String.valueOf(fValue);
    value = value.replaceFirst("\\.*0*$", "");

    return value;

}

From source file:Main.java

public static <T> String join(Collection<T> col, String separator) {
    String ret = "";
    if (col != null && col.size() > 0) {
        for (Object x : col) {
            if (x instanceof String) {
                ret += separator + (String) x;
            } else {
                ret += separator + x.toString();
            }/*from  ww w .  ja  v a  2 s.  c  om*/
        }
    }
    return ret.replaceFirst(separator, "");

}