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:com.uber.jenkins.phabricator.coverage.CoberturaXMLParser.java

private List<String> getSourceDirs(Document doc) {
    if (workspace == null) {
        return Collections.emptyList();
    }//w  w w .  ja  v a2  s.  c o  m

    List<String> sourceDirs = new ArrayList<String>();
    NodeList sources = doc.getElementsByTagName(TAG_NAME_SOURCE);
    for (int i = 0; i < sources.getLength(); i++) {
        Node source = sources.item(i);
        String srcDir = source.getTextContent();
        if (srcDir.contains(workspace + "/")) {
            String relativeSrcDir = srcDir.replaceFirst(workspace + "/", "");
            if (!relativeSrcDir.isEmpty()) {
                sourceDirs.add(relativeSrcDir);
            }
        }
    }
    return sourceDirs;
}

From source file:info.dolezel.fatrat.plugins.helpers.JarClassLoader.java

private Set<Class> findClasses(File directory, String packageName, Class annotation)
        throws ClassNotFoundException, IOException {
    Set<Class> classes = new HashSet<Class>();
    if (!directory.exists()) {

        String fullPath = directory.toString();
        String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
        JarFile jarFile = new JarFile(jarPath);
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            String entryName = entry.getName();
            if (entryName.endsWith(".class") && !entryName.contains("$")) {
                String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
                Class cls = this.loadClass(className);

                if (annotation == null || cls.isAnnotationPresent(annotation))
                    classes.add(cls);/*  w  w w .j  a  v a 2  s . c om*/
            }
        }
    } else {
        File[] files = directory.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                assert !file.getName().contains(".");
                classes.addAll(findClasses(file, packageName + "." + file.getName(), annotation));
            } else if (file.getName().endsWith(".class")) {
                Class cls = this.loadClass(
                        packageName + '.' + file.getName().substring(0, file.getName().length() - 6));

                if (annotation == null || cls.isAnnotationPresent(annotation))
                    classes.add(cls);
            }
        }
    }
    return classes;
}

From source file:org.fcrepo.kernel.impl.identifiers.HttpPidMinter.java

/**
 * Remove unwanted text from the minter service response to produce the desired identifer.
 * Override this method for processing more complex than a simple regex replacement.
**///from w  w  w  . j  av  a 2s .  c  o m
protected String responseToPid(final String responseText) throws Exception {
    log.debug("responseToPid({})", responseText);
    if (!isBlank(regex)) {
        return responseText.replaceFirst(regex, "");
    } else if (xpath != null) {
        return xpath(responseText, xpath);
    } else {
        return responseText;
    }
}

From source file:it.delli.mwebc.utils.DefaultCastHelper.java

private Color toColor(String value) throws ParseException {
    return new Color(Integer.parseInt(value.replaceFirst("#", ""), 16));
}

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactoryTest.java

private CoreContainer init() throws Exception {

    if (solrHomeDirectory.exists()) {
        FileUtils.deleteDirectory(solrHomeDirectory);
    }//from ww w  .j  av a 2s  .  co  m
    assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());

    copyMinConf(new File(solrHomeDirectory, "source"));
    File target = new File(solrHomeDirectory, "target");
    copyMinConf(target);
    // modify the target to add SidecarIndexReaderFactory
    File targetSolrConf = new File(target, "conf" + File.separator + "solrconfig.xml");
    String xml = FileUtils.readFileToString(targetSolrConf, "UTF-8");
    xml = xml.replaceFirst("<!-- EDIT_SIDECAR_START", "");
    xml = xml.replaceFirst("EDIT_SIDECAR_END -->", "");
    FileUtils.writeStringToFile(targetSolrConf, xml, "UTF-8");
    File solrXml = new File(solrHomeDirectory, "solr.xml");
    FileUtils.write(solrXml, SOLR_XML, IOUtils.CHARSET_UTF_8.toString());
    final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
    cores.load();

    //cores.setPersistent(false);
    return cores;
}

From source file:com.teambrmodding.neotech.registries.CrusherRecipeHandler.java

@Override
protected void generateDefaultRecipes() {
    LogHelper.logger.info("[Neotech] Creating Crusher Recipe List...");

    addRecipe(new CrusherRecipe("oreRedstone", "dustRedstone:12", "dustRedstone:4", 20));
    addRecipe(new CrusherRecipe("oreLapis", "gemLapis:8", "gemLapis:2", 20));
    addRecipe(new CrusherRecipe(getItemStackString(new ItemStack(Items.BLAZE_ROD)),
            getItemStackString(new ItemStack(Items.BLAZE_POWDER, 4)),
            getItemStackString(new ItemStack(Items.BLAZE_POWDER, 2)), 15));
    addRecipe(new CrusherRecipe("cobblestone", "sand:2", "gravel:1", 10));
    addRecipe(new CrusherRecipe("sand", "gravel:2", "", 0));
    addRecipe(new CrusherRecipe("bone",
            getItemStackString(new ItemStack(Items.DYE, 8, EnumDyeColor.WHITE.getDyeDamage())),
            getItemStackString(new ItemStack(Items.DYE, 2, EnumDyeColor.WHITE.getDyeDamage())), 10));
    addRecipe(new CrusherRecipe("oreQuartz", "gemQuartz:4", "gemQuartz:2", 50));
    addRecipe(new CrusherRecipe(getItemStackString(new ItemStack(Blocks.CLAY)),
            getItemStackString(new ItemStack(Items.CLAY_BALL, 4)),
            getItemStackString(new ItemStack(Items.CLAY_BALL, 2)), 25));
    addRecipe(new CrusherRecipe(getItemStackString(new ItemStack(Blocks.HARDENED_CLAY)),
            getItemStackString(new ItemStack(Items.BRICK, 4)), "", 0));
    addRecipe(new CrusherRecipe("oreDiamond", "gemDiamond:2", "gemDiamond:1", 10));
    addRecipe(new CrusherRecipe("oreEmerald", "gemEmerald:2", "gemEmerald:1", 10));
    addRecipe(new CrusherRecipe("glowstone", "dustGlowstone:4", "dustGlowstone:2", 15));
    addRecipe(new CrusherRecipe("oreCoal", getItemStackString(new ItemStack(Items.COAL, 3)),
            getItemStackString(new ItemStack(Items.DIAMOND, 1)), 1));
    addRecipe(new CrusherRecipe("minecraft:wool:" + OreDictionary.WILDCARD_VALUE + ":1",
            getItemStackString(new ItemStack(Items.STRING, 4)), "", 0));
    addRecipe(new CrusherRecipe("blockGlass", "sand:1", "", 0));
    addRecipe(new CrusherRecipe("gravel", getItemStackString(new ItemStack(Items.FLINT, 3)),
            getItemStackString(new ItemStack(Items.FLINT, 1)), 20));

    // Adjust to Ore Dictionary
    String[] oreDictionary = OreDictionary.getOreNames();

    for (String entry : oreDictionary) {
        if (entry.startsWith("dust") && !doesRecipeExist(entry.replaceFirst("dust", "ore"))) {
            List<ItemStack> oreList = OreDictionary.getOres(entry.replaceFirst("dust", "ore"));
            if (!oreList.isEmpty()) {
                // We want a single type output
                List<ItemStack> dustList = OreDictionary.getOres(entry);
                if (!dustList.isEmpty())
                    addRecipe(new CrusherRecipe(entry.replaceFirst("dust", "ore"), getItemStackString(
                            new ItemStack(dustList.get(0).getItem(), 2, dustList.get(0).getItemDamage())), "",
                            0));/*from www. j ava2 s.c  o  m*/
            }
        } else if (entry.startsWith("ingot")) {
            List<ItemStack> dustList = OreDictionary.getOres(entry.replaceFirst("ingot", "dust"));
            if (!dustList.isEmpty() && !doesRecipeExist(entry.replaceFirst("ingot", "dust"))) {
                addRecipe(new CrusherRecipe(entry,
                        getItemStackString(
                                new ItemStack(dustList.get(0).getItem(), 1, dustList.get(0).getItemDamage())),
                        "", 0));
            }
        }
    }

    // Add Flower to Dyes
    for (IRecipe recipe : CraftingManager.getInstance().getRecipeList()) {
        if (recipe instanceof ShapelessRecipes) {
            ShapelessRecipes shapelessRecipe = (ShapelessRecipes) recipe;
            if (shapelessRecipe.recipeItems.size() == 1
                    && Block.getBlockFromItem(shapelessRecipe.recipeItems.get(0).getItem()) != null
                    && Block.getBlockFromItem(
                            shapelessRecipe.recipeItems.get(0).getItem()) instanceof BlockFlower) {
                String inputString = getItemStackString(shapelessRecipe.recipeItems.get(0));
                if (!doesRecipeExist(inputString))
                    addRecipe(new CrusherRecipe(inputString,
                            "dye:" + String.valueOf(shapelessRecipe.getRecipeOutput().getCount() * 2) + ":"
                                    + String.valueOf(shapelessRecipe.getRecipeOutput().getItemDamage()),
                            "", 0));
            }
        }
    }

    saveToFile();
}

From source file:ch.cyberduck.core.manta.MantaAccountHomeInfo.java

private Path buildNormalizedHomePath(final String rawHomePath) {
    final String defaultPath = StringUtils.defaultIfBlank(rawHomePath, Path.HOME);
    final String accountRootRegex = String.format("^/?(%s|~~?)/?", accountRoot.getAbsolute());
    final String subdirectoryRawPath = defaultPath.replaceFirst(accountRootRegex, "");

    if (StringUtils.isEmpty(subdirectoryRawPath)) {
        return accountRoot;
    }/*w  w w  .j ava 2 s  .  c om*/

    final String[] subdirectoryPathSegments = StringUtils.split(subdirectoryRawPath, Path.DELIMITER);
    Path homePath = accountRoot;

    for (final String pathSegment : subdirectoryPathSegments) {
        EnumSet<Path.Type> types = EnumSet.of(Path.Type.directory);
        if (homePath.getParent().equals(accountRoot)
                && StringUtils.equalsAny(pathSegment, HOME_PATH_PRIVATE, HOME_PATH_PUBLIC)) {
            types.add(Path.Type.volume);
        }

        homePath = new Path(homePath, pathSegment, types);
    }

    return homePath;
}

From source file:com.norconex.collector.http.data.HttpCrawlData.java

@Override
public final void setReference(String url) {
    super.setReference(url);
    if (url != null) {
        this.urlRoot = url.replaceFirst("(.*?://.*?)(/.*)", "$1");
    } else {//from   w  w  w . jav  a 2  s.  c  om
        this.urlRoot = null;
    }
}

From source file:edu.ucsd.crbs.cws.auth.AuthStringDecoderImpl.java

/**
 * Takes Basic HTTP Authentication string via <b>authString</b>
 * parameter in format:// w  w  w . j a  va  2 s .  co m
 * <p/>
 *
 * Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
 * <p/>
 *
 * and extracts login and password token from value to right of <b>Basic</b>
 * above which should be in format of <b>login:pass</b> once decoded via
 * {@link DatatypeConverter#parseBase64Binary(java.lang.String)} method
 *
 * @param auth Basic Http Authentication string in format above
 * @return {@link User} with {@link User#getLogin()} set to <b>login</b> and
 * {@link User#getToken()} set to <b>pass</b> or null if parse failed
 */
@Override
public User decodeAuthString(final String authString) {

    if (authString == null) {
        _log.log(Level.INFO, "Auth string is null");
        return null;
    }

    String authWithBasicRemoved = authString.replaceFirst("[B|b]asic ", "");
    byte[] decodedBytes = Base64.decodeBase64(authWithBasicRemoved);
    if (decodedBytes == null || decodedBytes.length == 0) {
        _log.log(Level.INFO, "Decoded byte array is null or size 0");
        return null;
    }
    String decodedUserPass = new String(decodedBytes);

    if (!decodedUserPass.contains(":")) {
        _log.log(Level.INFO, "Decoded auth information does not contain a colon");

        return null;
    }
    String[] userPass = decodedUserPass.split(":");

    if (userPass.length != 2) {
        _log.log(Level.INFO, "Decoded auth has more then 1 colon");

        return null;
    }
    if (userPass[0].length() == 0 || userPass[1].length() == 0) {
        _log.log(Level.INFO, "Login or token is size 0");

        return null;
    }

    User u = new User();
    u.setLogin(userPass[0]);
    u.setToken(userPass[1]);
    return u;
}

From source file:de.crowdcode.kissmda.core.uml.PackageHelper.java

/**
 * Get full package name./*from ww  w . j a va 2s  . c  o  m*/
 * 
 * @param clazz
 *            UML2 classifier
 * @param sourceDirectoryPackageName
 *            from the stereotype
 * @return full package name
 */
public String getFullPackageName(Classifier clazz, String sourceDirectoryPackageName) {
    // Get package until the beginning of SourceDirectory
    logger.log(Level.FINE, "Qualified name: " + clazz.getQualifiedName());
    // Remove the sourceDirectoryPackageName
    String toBeDeleted = sourceDirectoryPackageName + "::";
    String fullPackageName = clazz.getQualifiedName().replaceFirst(toBeDeleted, "");
    // Remove class name
    toBeDeleted = "::" + clazz.getName();
    fullPackageName = fullPackageName.replaceFirst(toBeDeleted, "");
    // Change :: to .
    fullPackageName = fullPackageName.replaceAll("::", ".");
    logger.log(Level.FINE, "Real package name: " + fullPackageName);
    return fullPackageName;
}