Example usage for org.apache.commons.lang StringUtils removeStart

List of usage examples for org.apache.commons.lang StringUtils removeStart

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils removeStart.

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the begining of a source string, otherwise returns the source string.

Usage

From source file:adalid.commons.properties.PropertiesHandler.java

private static String getArrayString(String[] values) {
    if (values == null) {
        return null;
    }/*from w ww . j  a  v  a 2s  . co m*/
    String s = "";
    String c = ", ";
    for (String value : values) {
        s += c + "\"" + StringUtils.trimToEmpty(value) + "\"";
    }
    return "{" + StringUtils.removeStart(s, c) + "}";
}

From source file:adalid.util.meta.sql.MetaPlatformSql.java

private void readPlatform(WriterContext basicWriterContext) {
    File platformPropertiesFile = platformBean.getPropertiesFile();
    logger.info("propertiesFile=" + platformPropertiesFile.getPath());
    try {/*from   w w w.  j  a va 2  s . com*/
        VelocityContext platformContext = basicWriterContext.getVelocityContextClone();
        platformContext.put(VC_PLATFORM, platform);
        TLB.setProgrammers(basicWriterContext.programmers);
        TLB.setWrapperClasses(basicWriterContext.wrapperClasses);
        putProperties(platformContext, platformPropertiesFile);
        Properties properties = mergeProperties(platformContext, platformPropertiesFile);
        putStrings(platformContext, properties);
        WriterContext platformWriterContext = newWriterContext(platformContext);
        File platformsFolder = platformPropertiesFile.getParentFile();
        ExtendedProperties platformExtendedProperties = PropertiesHandler
                .getExtendedProperties(platformPropertiesFile);
        String[] pathnames = platformExtendedProperties.getStringArray(FILE_RESOURCE_LOADER_PATH);
        String[] pathfilters = platformExtendedProperties.getStringArray(FILE_RESOURCE_LOADER_PATH_FILTER);
        Map<String, File> folders = new LinkedHashMap<>();
        if (pathnames == null || pathnames.length == 0) {
        } else {
            for (File folder : bootstrappingPlatformsFolders) {
                folders.putAll(FilUtils.directoriesMap(folder, pathnames, folder));
            }
        }
        if (pathfilters != null && pathfilters.length > 0) {
            String[] keyArray = folders.keySet().toArray(new String[folders.keySet().size()]);
            String slashedFilter, slashedPath;
            for (String pathfilter : pathfilters) {
                slashedFilter = pathfilter.replace(FILE_SEPARATOR, "/");
                for (String key : keyArray) {
                    slashedPath = key.replace(FILE_SEPARATOR, "/") + "/";
                    if (slashedPath.contains(slashedFilter)) {
                        folders.remove(key);
                        logger.debug(pathfilter + " excludes " + key);
                    }
                }
            }
        }
        File[] templateFiles;
        TemplateBean templateBean;
        String platformsFolderPath = platformsFolder.getPath(); // + FILE_SEPARATOR;
        for (File folder : folders.values()) {
            log(_detailLevel, "read", "path=" + StringUtils.removeStart(folder.getPath(), platformsFolderPath));
            templateFiles = folder.listFiles(propertiesFileFilter);
            Arrays.sort(templateFiles);
            for (File templatePropertiesFile : templateFiles) {
                templateBean = new TemplateBean(platformBean, templatePropertiesFile);
                readTemplate(platformWriterContext, templateBean);
                templates++;
            }
        }
        platforms++;
    } catch (Throwable throwable) {
        error(throwable);
    }
    printSummary();
}

From source file:com.egt.ejb.toolkit.ToolKitUtils.java

public static String getCodigoArchivoInforme(String codigoFuncion, String codigoDominio) {
    String alterno = StringUtils.trimToEmpty(codigoFuncion).toLowerCase();
    String dominio = StringUtils.trimToEmpty(codigoDominio).toLowerCase();
    alterno = StringUtils.removeStart(alterno, "emitir_");
    alterno = StringUtils.removeStart(alterno, "informar_");
    alterno = StringUtils.removeStart(alterno, "exportar_");
    alterno = StringUtils.removeStart(alterno, dominio);
    alterno = StringUtils.chomp(alterno, dominio);
    alterno = alterno.replace("_" + dominio + "_", "_");
    alterno = StringUtils.removeStart(alterno, "_");
    alterno = StringUtils.chomp(alterno, "_");
    alterno = dominio + "_" + alterno;
    return alterno;
}

From source file:net.sf.groovyMonkey.ScriptMetadata.java

public static String stripIllegalChars(final String string) {
    if (StringUtils.isBlank(string))
        return "";
    if (StringUtils.equals(string.trim(), ">"))
        return "_";
    final boolean prefix = string.trim().startsWith(">");
    final boolean postfix = string.trim().endsWith(">");
    final String processed = StringUtils.removeEnd(StringUtils.removeStart(string.trim(), ">"), ">");
    final StringBuffer buffer = new StringBuffer();
    if (processed.contains(">")) {
        for (final String str : StringUtils.stripAll(StringUtils.split(processed, ">"))) {
            final StringBuffer stripped = new StringBuffer(
                    compile("[^\\p{Alnum}_-]").matcher(str).replaceAll(""));
            buffer.append("__").append("" + stripped);
        }//  w  w w .j a v  a  2s  .c  om
    } else
        buffer.append(compile("[^\\p{Alnum}_-]").matcher(processed).replaceAll(""));
    if (prefix)
        buffer.insert(0, "_");
    if (postfix)
        buffer.append("_");
    return "" + buffer;
}

From source file:com.qualogy.qafe.business.resource.rdb.query.QueryToStringCreator.java

/**
 *
 * @param userFilledValue//from www. j  a  va2s  .  c om
 * @param userFirstUsedOperator
 * @return
 */
private static String getUserFilledValueWithoutFirstOperator(String userFilledValue,
        String userFirstUsedOperator) {
    String filledValueWithoutNotOperator = StringUtils.removeStart(userFilledValue, userFirstUsedOperator);

    //check if first operator has been removed from user input. Remove the
    //user operator by changing it to lowercase.
    if (filledValueWithoutNotOperator.length() == userFilledValue.length()) {
        filledValueWithoutNotOperator = StringUtils.removeStart(userFilledValue,
                userFirstUsedOperator.toLowerCase());
    }
    return filledValueWithoutNotOperator;
}

From source file:ch.cyberduck.core.ftp.FTPPath.java

/**
 * Parse response of MLSD/*  w w  w  . ja  v  a2  s  .c om*/
 *
 * @param children List to add parsed lines
 * @param replies  Lines
 * @return True if parsing is successful
 */
protected boolean parseMlsdResponse(final AttributedList<Path> children, List<String> replies) {

    if (null == replies) {
        // This is an empty directory
        return false;
    }
    boolean success = false; // At least one entry successfully parsed
    for (String line : replies) {
        final Map<String, Map<String, String>> file = this.parseFacts(line);
        if (null == file) {
            log.error(String.format("Error parsing line %s", line));
            continue;
        }
        for (String name : file.keySet()) {
            final Path parsed = new FTPPath(this.getSession(), this.getAbsolute(),
                    StringUtils.removeStart(name, this.getAbsolute() + Path.DELIMITER), FILE_TYPE);
            parsed.setParent(this);
            // size       -- Size in octets
            // modify     -- Last modification time
            // create     -- Creation time
            // type       -- Entry type
            // unique     -- Unique id of file/directory
            // perm       -- File permissions, whether read, write, execute is allowed for the login id.
            // lang       -- Language of the file name per IANA [11] registry.
            // media-type -- MIME media-type of file contents per IANA registry.
            // charset    -- Character set per IANA registry (if not UTF-8)
            for (Map<String, String> facts : file.values()) {
                if (!facts.containsKey("type")) {
                    log.error(String.format("No type fact in line %s", line));
                    continue;
                }
                if ("dir".equals(facts.get("type").toLowerCase(java.util.Locale.ENGLISH))) {
                    parsed.attributes().setType(DIRECTORY_TYPE);
                } else if ("file".equals(facts.get("type").toLowerCase(java.util.Locale.ENGLISH))) {
                    parsed.attributes().setType(FILE_TYPE);
                } else {
                    log.warn("Ignored type: " + line);
                    break;
                }
                if (name.contains(String.valueOf(DELIMITER))) {
                    if (!name.startsWith(this.getAbsolute() + Path.DELIMITER)) {
                        // Workaround for #2434.
                        log.warn("Skip listing entry with delimiter:" + name);
                        continue;
                    }
                }
                if (!success) {
                    if ("dir".equals(facts.get("type").toLowerCase(java.util.Locale.ENGLISH))
                            && this.getName().equals(name)) {
                        log.warn("Possibly bogus response:" + line);
                    } else {
                        success = true;
                    }
                }
                if (facts.containsKey("size")) {
                    parsed.attributes().setSize(Long.parseLong(facts.get("size")));
                }
                if (facts.containsKey("unix.uid")) {
                    parsed.attributes().setOwner(facts.get("unix.uid"));
                }
                if (facts.containsKey("unix.owner")) {
                    parsed.attributes().setOwner(facts.get("unix.owner"));
                }
                if (facts.containsKey("unix.gid")) {
                    parsed.attributes().setGroup(facts.get("unix.gid"));
                }
                if (facts.containsKey("unix.group")) {
                    parsed.attributes().setGroup(facts.get("unix.group"));
                }
                if (facts.containsKey("unix.mode")) {
                    try {
                        parsed.attributes()
                                .setPermission(new Permission(Integer.parseInt(facts.get("unix.mode"))));
                    } catch (NumberFormatException e) {
                        log.error(String.format("Failed to parse fact %s", facts.get("unix.mode")));
                    }
                }
                if (facts.containsKey("modify")) {
                    parsed.attributes().setModificationDate(this.parseTimestamp(facts.get("modify")));
                }
                if (facts.containsKey("create")) {
                    parsed.attributes().setCreationDate(this.parseTimestamp(facts.get("create")));
                }
                if (facts.containsKey("charset")) {
                    if (!facts.get("charset").equalsIgnoreCase(this.getSession().getEncoding())) {
                        log.error(String.format("Incompatible charset %s but session is configured with %s",
                                facts.get("charset"), this.getSession().getEncoding()));
                    }
                }
                children.add(parsed);
            }
        }
    }
    return success;
}

From source file:com.yoncabt.ebr.ui.ReportWindow.java

private void createMenuBar(MenuBar.MenuItem mainItem, File dir) throws IOException, JRException {
    //FIXME baz kodlar servise taabilir
    String menuText = dir.getName();
    File folderConfig = new File(dir, EBRParams.FOLDER_EBR_JSON);
    if (folderConfig.exists()) {
        try {/*from  w  ww . ja v a 2s. co m*/
            JSONObject jo = new JSONObject(FileUtils.readFileToString(folderConfig, "utf-8"));
            menuText = jo.optString("label", menuText);
        } catch (IOException ex) {
            throw new IOException(folderConfig.getAbsolutePath(), ex);
        } catch (JSONException ex) {
            throw new JSONException(new RuntimeException(folderConfig.getAbsolutePath(), ex));
        }
    }
    MenuBar.MenuItem menuItem = mainItem.addItem(menuText, null);

    for (File file : dir.listFiles()) {
        if (file.getName().charAt(0) == '.') {
            continue;//gereksiz ama olduu belli olsun
        } else if (file.isDirectory()) {
            createMenuBar(menuItem, file);
        } else if (file.getName().endsWith(".sql") || file.getName().endsWith(".jrxml")) {
            BaseReport r = file.getName().endsWith(".sql") ? new SQLReport() : new JasperReport();
            context.getAutowireCapableBeanFactory().autowireBean(r);
            String text;
            try {
                text = r.loadDefinition(file).getCaption();
            } catch (ReportException ex) {
                Notification.show("Hata", Notification.Type.ERROR_MESSAGE);
                Logger.getLogger(ReportWindow.class.getName()).log(Level.SEVERE, null, ex);
                text = file.getName() + " ERROR";
            }
            menuItem.addItem(text, (MenuBar.MenuItem selectedItem) -> {
                System.out.println(r.getFile() + " altrlacak");
                String frag = StringUtils.removeStart(r.getFile().getAbsolutePath(),
                        EBRConf.INSTANCE.getValue(EBRParams.REPORTS_JRXML_PATH, ""));
                frag = StringUtils.removeStart(frag, "/");
                getPage().setUriFragment(frag);
            });
        } else if (file.getName().endsWith(".jrxml")) {//FIXME support for compiled jasper files
            final JasperReport r = new JasperReport();
            context.getAutowireCapableBeanFactory().autowireBean(r);
            String text = r.loadDefinition(file).getCaption();
            menuItem.addItem(text, (MenuBar.MenuItem selectedItem) -> {
                System.out.println(r.getFile() + " altrlacak");
                String frag = StringUtils.removeStart(r.getFile().getAbsolutePath(),
                        EBRConf.INSTANCE.getValue(EBRParams.REPORTS_JRXML_PATH, ""));
                frag = StringUtils.removeStart(frag, "/");
                getPage().setUriFragment(frag);
            });
        }
    }
}

From source file:com.egt.core.util.EA.java

private static String get(String name) {
    String key = name;/*  w w w.java  2  s. c  o m*/
    String value = System.getenv(key);
    if (StringUtils.isBlank(value)) {
        key = name.replace('_', '.').toLowerCase();
        value = System.getProperties().getProperty(key);
        if (StringUtils.isBlank(value)) {
            key = StringUtils.removeStart(name, SEV.ENT_APP_VAR_PREFFIX);
            value = bootstrapping.getProperty(key, "");
        }
    }
    show(key, value);
    return StringUtils.trimToEmpty(value);
}

From source file:adalid.core.programmers.AbstractJavaProgrammer.java

protected String javaLangLess(Class<?> type) {
    return type == null ? "Object"
            : type.isArray() ? javaLangLess(type.getComponentType()) + "[]"
                    : StringUtils.removeStart(type.getName(), "java.lang.");
}

From source file:edu.mayo.cts2.framework.webapp.rest.controller.CodeSystemVersionController.java

@RequestMapping(value = { PATH_CODESYSTEMBYID + "/" + ENTITY + "/" + ALL_WILDCARD,
        PATH_CODESYSTEMBYID + "/" + ENTITIES }, method = RequestMethod.GET)
public ModelAndView getCodeSystemVersionOfCodeSystemByTagRedirect(HttpServletRequest httpServletRequest,
        RestReadContext restReadContext, QueryControl queryControl,
        @PathVariable(VAR_CODESYSTEMID) String codeSystemName,
        @RequestParam(value = PARAM_TAG, defaultValue = DEFAULT_TAG) String tag,
        @RequestParam(value = "redirect", defaultValue = DEFAULT_REDIRECT) boolean redirect) {

    //TODO: Accept tag URIs here
    VersionTagReference tagReference = new VersionTagReference(tag);

    String codeSystemVersionName = this.codeSystemVersionNameResolver.getVersionNameFromTag(
            codeSystemVersionReadService, ModelUtils.nameOrUriFromName(codeSystemName), tagReference,
            this.resolveRestReadContext(restReadContext));

    String contextPath = this.getUrlPathHelper().getContextPath(httpServletRequest);

    String requestUri = StringUtils.removeStart(this.getUrlPathHelper().getRequestUri(httpServletRequest),
            contextPath);/*from   w w  w.j av  a2 s .c  om*/

    requestUri = StringUtils.removeStart(requestUri, "/");

    requestUri = StringUtils.replaceOnce(requestUri, CODESYSTEM + "/" + codeSystemName + "/",
            CODESYSTEM + "/" + codeSystemName + "/" + VERSION + "/" + codeSystemVersionName + "/");

    if (redirect) {
        @SuppressWarnings("unchecked")
        Map<String, Object> parameters = new HashMap<String, Object>(httpServletRequest.getParameterMap());

        parameters.remove(PARAM_REDIRECT);

        return new ModelAndView("redirect:" + "/" + requestUri + this.mapToQueryString(parameters));
    } else {
        return new ModelAndView("forward:" + "/" + requestUri);
    }
}