Example usage for org.apache.commons.lang3 StringUtils substringBefore

List of usage examples for org.apache.commons.lang3 StringUtils substringBefore

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringBefore.

Prototype

public static String substringBefore(final String str, final String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:org.apache.unomi.services.actions.ActionExecutorDispatcher.java

@SuppressWarnings("unchecked")
private boolean hasContextualParameter(Map<String, Object> values) {
    for (Map.Entry<String, Object> entry : values.entrySet()) {
        Object value = entry.getValue();
        if (value instanceof String) {
            String s = (String) value;
            if (s.contains(VALUE_NAME_SEPARATOR)
                    && valueExtractors.containsKey(StringUtils.substringBefore(s, VALUE_NAME_SEPARATOR))) {
                return true;
            }//from   w  w w.j  av a 2 s  .co m
        } else if (value instanceof Map) {
            if (hasContextualParameter((Map<String, Object>) value)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.blockartistry.mod.ThermalRecycling.support.ModThermalRecycling.java

@Override
public void apply() {

    // Register special scrap handlers
    final ThermalRecyclingScrapHandler handler = new ThermalRecyclingScrapHandler();
    // Need to be able to see any special frames in real time.
    ScrapHandler.registerHandler(new ItemStack(ItemManager.processingCore, 1, OreDictionary.WILDCARD_VALUE),
            handler);/*from   w ww.ja v a2  s.c  om*/

    ItemData.setRecipeIgnored(ItemManager.recyclingScrapBox, true);
    ItemData.setRecipeIgnored(ItemManager.debris, true);
    ItemData.setRecipeIgnored(BlockManager.scrapBlock, true);
    ItemData.setRecipeIgnored(ItemManager.material, true);
    ItemData.setRecipeIgnored(ItemManager.paperLogMaker, true);

    ItemData.setValue(new ItemStack(ItemManager.debris), ScrapValue.NONE);
    ItemData.setValue(new ItemStack(BlockManager.scrapBlock), ScrapValue.NONE);
    ItemData.setValue(new ItemStack(ItemManager.paperLogMaker), ScrapValue.NONE);

    ItemData.setValue(new ItemStack(ItemManager.material, 1, Material.PAPER_LOG), ScrapValue.POOR);

    ItemData.setValue(new ItemStack(ItemManager.recyclingScrap, 1, RecyclingScrap.POOR), ScrapValue.POOR);
    ItemData.setValue(new ItemStack(ItemManager.recyclingScrap, 1, RecyclingScrap.STANDARD),
            ScrapValue.STANDARD);
    ItemData.setValue(new ItemStack(ItemManager.recyclingScrap, 1, RecyclingScrap.SUPERIOR),
            ScrapValue.SUPERIOR);
    ItemData.setValue(new ItemStack(ItemManager.recyclingScrapBox, 1, RecyclingScrap.POOR), ScrapValue.POOR);
    ItemData.setValue(new ItemStack(ItemManager.recyclingScrapBox, 1, RecyclingScrap.STANDARD),
            ScrapValue.STANDARD);
    ItemData.setValue(new ItemStack(ItemManager.recyclingScrapBox, 1, RecyclingScrap.SUPERIOR),
            ScrapValue.SUPERIOR);

    // ////////////////////
    //
    // Add recipe blacklist items first
    // before processing!
    //
    // ////////////////////

    // ////////////////////
    //
    // Process the recipes
    //
    // ////////////////////

    //final String modIds = ":" + MyUtils.join(":", whiteList) + ":";
    final String modIds = ":" + StringUtils.join(whiteList, ":") + ":";

    // Process all registered recipes
    for (final Object o : CraftingManager.getInstance().getRecipeList()) {

        final IRecipe recipe = (IRecipe) o;
        final ItemStack stack = recipe.getRecipeOutput();

        // Check to see if this item should have a recipe in
        // the list. This does not mean that something later
        // on can't add one - just means by default it will
        // not be included.
        if (stack != null) {
            if (!ItemData.isRecipeIgnored(stack)) {

                // If the name is prefixed with any of the mods
                // we know about then we can create the recipe.
                final String name = Item.itemRegistry.getNameForObject(stack.getItem());

                if (modIds.contains(":" + StringUtils.substringBefore(name, ":") + ":")) {
                    try {
                        recycler.useRecipe(recipe).save();
                    } catch (Throwable t) {
                        ModLog.catching(t);
                    }
                }
            }
        }
    }

    // Apply the blacklist from the configuration.  We need to fix up
    // each entry with a ^ so the underlying routine just does what it
    // needs to do.
    for (final String s : ModOptions.getRecyclerBlacklist()) {
        registerItemBlockedFromScrapping(true, "^" + s);
    }

    // Lock our tables
    ItemData.freeze();
    RecipeData.freeze();
    ScrapHandler.freeze();

    // Register scrap items for Pile of Rubble
    PileOfRubble.addRubbleDrop(ScrappingTables.poorScrap, 1, 2, 5);
    PileOfRubble.addRubbleDrop(ScrappingTables.poorScrapBox, 1, 1, 2);
    PileOfRubble.addRubbleDrop(ScrappingTables.standardScrap, 1, 2, 4);
    PileOfRubble.addRubbleDrop(ScrappingTables.standardScrapBox, 1, 1, 1);
}

From source file:org.blockartistry.mod.ThermalRecycling.support.SupportedMod.java

public static boolean isModWhitelisted(final String itemId) {
    if (modIdString == null)
        modIdString = SEPARATOR + StringUtils.join(getEffectiveModIdList(), SEPARATOR) + SEPARATOR;
    final String modId = StringUtils.substringBefore(itemId, SEPARATOR);
    return modId == null || modId.isEmpty() ? false : modIdString.contains(SEPARATOR + modId + SEPARATOR);
}

From source file:org.bonitasoft.engine.bdm.client.ResourcesLoader.java

private String packageOf(final String javaFile, String originalPackage) {
    String firstChar = StringUtils.substringBefore(originalPackage, ".");
    String className = javaFile.substring(javaFile.indexOf(firstChar));
    return className.substring(0, className.lastIndexOf("/"));
}

From source file:org.bonitasoft.engine.business.data.generator.client.ResourcesLoader.java

static String packageOf(final String javaFile, String originalPackage) {
    String firstChar = StringUtils.substringBefore(originalPackage, ".");
    String className = javaFile.substring(javaFile.indexOf(firstChar));
    if (className.indexOf("!") != -1) {//support osgi classpath url
        className = className.substring(className.indexOf("!") + 2, className.length());
    }//  ww  w .  j  av a2  s.c  o m
    return className.substring(0, className.lastIndexOf("/"));
}

From source file:org.brekka.paveway.web.servlet.UploadServlet.java

protected UploadingFilesContext getFilesContext(final HttpServletRequest req) {
    String contextPath = req.getContextPath();
    String requestURI = req.getRequestURI();
    requestURI = requestURI.substring(contextPath.length());
    String remainder = requestURI.substring(req.getServletPath().length() + 1);
    String makerKey = StringUtils.substringBefore(remainder, "/");
    UploadsContext bundleMakerContext = UploadsContext.get(req, true);
    return bundleMakerContext.get(makerKey);
}

From source file:org.cleverbus.core.alerts.AlertsJmxConfiguration.java

private AlertInfo getAlert(String attrName) throws AttributeNotFoundException {
    String alertId;/*  ww  w  .  ja  v a2s.  c  om*/
    if (StringUtils.endsWith(attrName, ENABLE_SUFFIX)) {
        alertId = StringUtils.substringBefore(attrName, ENABLE_SUFFIX);
    } else if (StringUtils.endsWith(attrName, LIMIT_SUFFIX)) {
        alertId = StringUtils.substringBefore(attrName, LIMIT_SUFFIX);
    } else {
        throw new AttributeNotFoundException("attribute name is not in expected format");
    }

    AlertInfo alert = configuration.findAlert(alertId);

    if (alert == null) {
        throw new AttributeNotFoundException("There is no alert for id '" + alertId + "'");
    }

    return alert;
}

From source file:org.cryptomator.crypto.aes256.Aes256Cryptor.java

/**
 * @see #encryptPathComponent(String, SecretKey, CryptorIOSupport)
 *//*from   w w  w .  j av  a2  s.c  om*/
private String decryptPathComponent(final String encrypted, final SecretKey key, CryptorIOSupport ioSupport)
        throws IllegalBlockSizeException, BadPaddingException, IOException {
    final String ivAndCiphertext;
    if (encrypted.endsWith(LONG_NAME_FILE_EXT)) {
        final String basename = StringUtils.removeEnd(encrypted, LONG_NAME_FILE_EXT);
        final String crc32 = StringUtils.substringBefore(basename, LONG_NAME_PREFIX_SEPARATOR);
        final String uuid = StringUtils.substringAfter(basename, LONG_NAME_PREFIX_SEPARATOR);
        final String metadataFilename = crc32 + METADATA_FILE_EXT;
        final LongFilenameMetadata metadata = this.getMetadata(ioSupport, metadataFilename);
        ivAndCiphertext = metadata.getEncryptedFilenameForUUID(UUID.fromString(uuid));
    } else if (encrypted.endsWith(BASIC_FILE_EXT)) {
        ivAndCiphertext = StringUtils.removeEndIgnoreCase(encrypted, BASIC_FILE_EXT);
    } else {
        throw new IllegalArgumentException("Unsupported path component: " + encrypted);
    }

    final String partialIvStr = StringUtils.substringBefore(ivAndCiphertext, IV_PREFIX_SEPARATOR);
    final String ciphertext = StringUtils.substringAfter(ivAndCiphertext, IV_PREFIX_SEPARATOR);
    final ByteBuffer iv = ByteBuffer.allocate(AES_BLOCK_LENGTH);
    iv.put(ENCRYPTED_FILENAME_CODEC.decode(partialIvStr));

    final Cipher cipher = this.aesCtrCipher(key, iv.array(), Cipher.DECRYPT_MODE);
    final byte[] encryptedBytes = ENCRYPTED_FILENAME_CODEC.decode(ciphertext);
    final byte[] paddedCleartextBytes = cipher.doFinal(encryptedBytes);

    // remove NULL padding (not valid in file names anyway)
    final int beginOfPadding = ArrayUtils.indexOf(paddedCleartextBytes, (byte) 0x00);
    if (beginOfPadding == -1) {
        return new String(paddedCleartextBytes, StandardCharsets.UTF_8);
    } else {
        final byte[] cleartextBytes = Arrays.copyOf(paddedCleartextBytes, beginOfPadding);
        return new String(cleartextBytes, StandardCharsets.UTF_8);
    }
}

From source file:org.dederem.common.service.VersionAnalyseService.java

/**
 * Read method for "Packages" file./* www  . j ava2s  .  co  m*/
 *
 * @param input
 *            InputStream on the text file
 * @return The object populated with the content of the file.
 * @throws IOException
 *             I/O error.
 */
public final DebVersion analyzeFile(final String suite, final InputStream input) throws IOException {
    final DebVersion result = new DebVersion();

    final Map<String, StringBuilder> data = new HashMap<>();
    StringBuilder lastData = null; // NOPMD - init

    final BufferedReader reader = new BufferedReader(new InputStreamReader(input, Charsets.UTF_8));
    String line = reader.readLine();
    while (line != null) {
        if (line.isEmpty()) {
            // manage the end of the bloc
            final DebPackageDesc pkgDesc = this.readPackageDesc(data);
            if (pkgDesc != null) {
                // check if file already present in the repository
                final DebPackageDesc local = this.repoService.getPackageInLocalRepo(suite,
                        pkgDesc.getDebPackage());
                if (local == null) {
                    // add the package to package list.
                    result.getPackages().add(pkgDesc);
                } else {
                    if (this.repoService.checkPackageEquality(pkgDesc, local)) {
                        // add the package to package list.
                        result.getPackages().add(local);
                    } else {
                        // add the package to package list.
                        result.getPackages().add(pkgDesc);
                    }
                }
            }
            data.clear();
        } else {
            // manage a new entry in the current bloc
            if (Character.isWhitespace(line.charAt(0))) {
                if (lastData != null) {
                    lastData.append(line);
                }
            } else {
                final String key = StringUtils.substringBefore(line, ":");
                final String value = StringUtils.substringAfter(line, ":");
                lastData = new StringBuilder(value);
                data.put(key, lastData);
            }
        }
        line = reader.readLine();
    }
    result.setSuite(suite);
    return result;
}

From source file:org.eclipse.recommenders.utils.rcp.CompilerBindings.java

public static Optional<IMethodName> toMethodName(@Nullable final MethodBinding binding) {
    if (binding == null) {
        return absent();
    }/*from   ww  w .  j  a v  a 2s .c  o m*/
    try {
        final String uniqueKey = String.valueOf(binding.computeUniqueKey());
        String qualifiedMethodName = StringUtils.substringBefore(uniqueKey, "(").replace(";.", ".");
        if (qualifiedMethodName.endsWith("."))
            qualifiedMethodName += new String(TypeConstants.INIT);
        final String[] parameterTypes = Signature.getParameterTypes(uniqueKey);
        final String returnType = Signature.getReturnType(uniqueKey);
        final StringBuilder sb = new StringBuilder();
        sb.append(qualifiedMethodName).append("(");
        for (final String parameter : parameterTypes) {
            sb.append(parameter);
        }
        sb.append(")").append(returnType);
        final IMethodName res = VmMethodName.get(sb.toString());
        return of(res);
    } catch (final RuntimeException e) {
        // if the signature could not be parsed by JDT (because it is incomplete!):
        return absent();
    }
}