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

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

Introduction

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

Prototype

public static String replaceChars(String str, String searchChars, String replaceChars) 

Source Link

Document

Replaces multiple characters in a String in one go.

Usage

From source file:org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifestEntity.java

private void createEntityMetaData(File file, String userId, String projectId, Boolean isFolder,
        Boolean isHidden) {//from  ww  w .  j a v a  2s.c  o  m
    if (LocaleHelper.getLocale() == null) {
        LocaleHelper.setLocale(Locale.getDefault());
    }
    entityMetaData = new EntityMetaData();
    entityMetaData.setCreatedBy(userId);
    entityMetaData.setCreatedDate(XmlGregorianCalendarConverter.asXMLGregorianCalendar(new Date()));
    entityMetaData.setDescription("Project folder for AgileBi Project named: " + projectId);
    entityMetaData.setIsHidden(isHidden);
    entityMetaData.setIsFolder(isFolder);
    entityMetaData.setLocale(LocaleHelper.getLocale().toString());
    entityMetaData.setName(file.getName());
    entityMetaData.setPath(StringUtils.replaceChars(file.getPath(), "/\\", "//"));
    entityMetaData.setTitle(file.getName());
    setPath(StringUtils.replaceChars(file.getPath(), "/\\", "//"));
}

From source file:org.piraso.ui.base.SaveMonitorInstanceDialog.java

private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed
    File home = new File(System.getProperty("user.home"));
    File pirasoDir = new File(home, "piraso");
    File pirasoSaveDir = new File(pirasoDir, "saved");
    if (!pirasoSaveDir.isDirectory()) {
        pirasoSaveDir.mkdirs();//from   w  w  w  .java 2 s.com
    }

    JFileChooser browserFileChooser = new FileChooserBuilder("piraso-saved-dir")
            .setTitle(NbBundle.getMessage(SaveMonitorInstanceDialog.class,
                    "SaveMonitorInstanceDialog.browser.title"))
            .setFileFilter(new PirasoFileFilter()).setDefaultWorkingDirectory(pirasoSaveDir)
            .createFileChooser();

    String replaceName = StringUtils.replaceChars(name, "[]", "");
    if (!replaceName.endsWith(String.format(".%s", PirasoFileFilter.EXTENSION))) {
        replaceName = String.format("%s.%s", replaceName, PirasoFileFilter.EXTENSION);
    }

    browserFileChooser.setSelectedFile(new File(pirasoSaveDir, replaceName));
    int result = browserFileChooser.showDialog(this, NbBundle.getMessage(SaveMonitorInstanceDialog.class,
            "SaveMonitorInstanceDialog.browser.approveText"));

    if (JFileChooser.APPROVE_OPTION == result) {
        txtTargetFile.setText(browserFileChooser.getSelectedFile().getAbsolutePath());
        refreshButtons();
    }
}

From source file:org.redpill.alfresco.pdfapilot.worker.PdfaPilotWorker.java

private String getBasename(NodeRef node) {
    if (node == null || !_nodeService.exists(node)) {
        return "PPCTW_" + GUID.generate();
    }/*from   w ww.  j  a v  a 2  s. c om*/

    try {
        String filename = (String) _nodeService.getProperty(node, ContentModel.PROP_NAME);

        String basename = FilenameUtils.getBaseName(filename);

        // TODO: Investigate if this is really needed
        // callas currently has a bug that makes it crash if the whole filepath is
        // longer than 260 characters
        basename = StringUtils.substring(basename, 0, 100);

        // 0x2013 is the long hyphen, not allowed here...
        char c = 0x2013;
        if (StringUtils.contains(basename, c)) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Long hyphen replaced with short one");
            }

            basename = StringUtils.replaceChars(basename, c, '-');
        }

        filename = basename;

        if (LOG.isTraceEnabled()) {
            LOG.trace("Filename before normalization");

            for (char character : filename.toCharArray()) {
                LOG.trace(character + " : " + (int) character);
            }
        }

        filename = Normalizer.normalize(filename, Form.NFKC);

        if (LOG.isTraceEnabled()) {
            LOG.trace("Filename after normalization");

            for (char character : filename.toCharArray()) {
                LOG.trace(character + " : " + (int) character);
            }
        }

        // pad the string with _ until it's at lest 3 characters long
        if (basename.length() < 3) {
            basename = StringUtils.rightPad(basename, 3, "_");
        }

        return basename;
    } catch (final Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.richfaces.tests.metamer.ftest.MetamerTestInfo.java

private static String getFilename(String packageName, String className, String methodName) {
    String testInfo = getConfigurationInfo();
    testInfo = StringUtils.replaceChars(testInfo, "\\/*?\"<>|", "");
    testInfo = StringUtils.replaceChars(testInfo, "\r\n \t", "_");
    testInfo = StringUtils.replaceChars(testInfo, ":", "-");

    // derives template and sort it as sub-directory after other attributes
    Matcher matcher = Pattern.compile("^(template-[^;]+);(.*)$").matcher(testInfo);
    if (matcher.find()) {
        testInfo = matcher.group(2) + "/" + matcher.group(1);
    }//from w w  w .ja v a 2 s .  co  m

    return packageName + "/" + className + "/" + methodName + "/" + testInfo;
}

From source file:org.sakaiproject.component.impl.BasicConfigurationService.java

public Locale getLocaleFromString(String localeString) {
    // should this just use LocalUtils.toLocale()? - can't - it thinks en_GB is invalid for example
    if (localeString != null) {
        // force en-US (dash separated) values into underscore style
        localeString = StringUtils.replaceChars(localeString, '-', '_');
    } else {/*from w  w  w .j  av  a2 s  .c o m*/
        return null;
    }
    String[] locValues = localeString.trim().split("_");
    if (locValues.length >= 3 && StringUtils.isNotBlank(locValues[2])) {
        return new Locale(locValues[0], locValues[1], locValues[2]); // language, country, variant
    } else if (locValues.length == 2 && StringUtils.isNotBlank(locValues[1])) {
        return new Locale(locValues[0], locValues[1]); // language, country
    } else if (locValues.length == 1 && StringUtils.isNotBlank(locValues[0])) {
        return new Locale(locValues[0]); // language
    } else {
        return Locale.getDefault();
    }
}

From source file:org.sakaiproject.user.impl.BaseUserDirectoryService.java

/**
 * Adjust the eid - trim it to null, and lower case IF we are case insensitive.
 *
 * @param eid// w ww . j a v  a2 s  . c  o  m
 *        The eid to clean up.
 * @return A cleaned up eid.
 */
protected String cleanEid(String eid) {
    eid = StringUtils.lowerCase(eid);
    eid = StringUtils.trimToNull(eid);

    if (eid != null) {
        // remove all instances of these chars <>,;:\"
        eid = StringUtils.replaceChars(eid, "<>,;:\\/", "");
    }
    // NOTE: length check is handled later on
    return eid;
}

From source file:org.sonar.api.qualitymodel.Characteristic.java

public Characteristic setName(String s, boolean asKey) {
    this.name = StringUtils.trimToNull(s);
    if (asKey) {/*from w  ww  . j  a va 2  s . co m*/
        this.key = StringUtils.upperCase(this.name);
        this.key = StringUtils.replaceChars(this.key, ' ', '_');
    }
    return this;
}

From source file:org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic.java

public DefaultCharacteristic setName(String s, boolean asKey) {
    this.name = StringUtils.trimToNull(s);
    if (asKey) {//from   w w  w . ja  v  a2s .  c o  m
        this.key = StringUtils.upperCase(this.name);
        this.key = StringUtils.replaceChars(this.key, ' ', '_');
    }
    return this;
}

From source file:org.sonar.application.JettyEmbedderTest.java

@Test
public void shouldLoadPluginsClasspath() throws Exception {
    JettyEmbedder jetty = new JettyEmbedder("127.0.0.1", 9999);

    String classpath = jetty/* w  w w  .j a v  a 2  s.co  m*/
            .getPluginsClasspath("/org/sonar/application/JettyEmbedderTest/shouldLoadPluginsClasspath");
    classpath = StringUtils.replaceChars(classpath, "\\", "/");

    assertThat(classpath)
            .contains("org/sonar/application/JettyEmbedderTest/shouldLoadPluginsClasspath/plugin1.jar");
    assertThat(classpath)
            .contains("org/sonar/application/JettyEmbedderTest/shouldLoadPluginsClasspath/plugin1.jar");
    assertThat(classpath)
            .contains("org/sonar/application/JettyEmbedderTest/shouldLoadPluginsClasspath/plugin2.jar");

    // important : directories end with /
    assertThat(classpath).contains("org/sonar/application/JettyEmbedderTest/shouldLoadPluginsClasspath/,");
}

From source file:org.sonar.batch.scan.ProjectReactorBuilderTest.java

/**
 * Search for a resource in the classpath. For example calling the method getResource(getClass(), "myTestName/foo.txt") from
 * the class org.sonar.Foo loads the file $basedir/src/test/resources/org/sonar/Foo/myTestName/foo.txt
 *
 * @return the resource. Null if resource not found
 *//*from  www. j a  v  a2 s .  com*/
public static File getResource(Class baseClass, String path) {
    String resourcePath = StringUtils.replaceChars(baseClass.getCanonicalName(), '.', '/');
    if (!path.startsWith("/")) {
        resourcePath += "/";
    }
    resourcePath += path;
    return getResource(resourcePath);
}