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.beangle.model.persist.hibernate.HibernateEntityDao.java

public int update(Class<?> entityClass, String attr, Object[] values, Map<String, Object> updateParams) {
    if (null == values || values.length == 0 || updateParams.isEmpty()) {
        return 0;
    }/*from   w  w  w  .  j a v  a 2  s. c  o m*/
    String entityName = entityClass.getName();
    StringBuilder hql = new StringBuilder();
    hql.append("update ").append(entityName).append(" set ");
    Map<String, Object> newParams = CollectUtils.newHashMap();
    for (final String parameterName : updateParams.keySet()) {
        if (null == parameterName) {
            continue;
        }
        String locateParamName = StringUtils.replaceChars(parameterName, '.', '_');
        hql.append(parameterName).append(" = ").append(":").append(locateParamName).append(",");
        newParams.put(locateParamName, updateParams.get(locateParamName));
    }
    hql.deleteCharAt(hql.length() - 1);
    hql.append(" where ").append(attr).append(" in (:ids)");
    newParams.put("ids", values);
    return executeUpdateHql(hql.toString(), newParams);
}

From source file:org.betaconceptframework.astroboa.commons.excelbuilder.ExcelSheetBuilder.java

private Sheet instantiateSheet(HSSFWorkbook workbook) {

    ContentObjectTypeDefinition contentObjectTypeDefinition = (ContentObjectTypeDefinition) definitionService
            .getCmsDefinition(contentType, ResourceRepresentationType.DEFINITION_INSTANCE, false);

    //Reorder property paths
    DefinitionOrderHelper definitionOrderHelper = new DefinitionOrderHelper();
    contentObjectTypeDefinition.accept(definitionOrderHelper);

    Collections.sort(propertyPaths, definitionOrderHelper);

    // create a new sheet
    if (contentObjectTypeDefinition.getDisplayName() == null || StringUtils
            .isBlank(contentObjectTypeDefinition.getDisplayName().getAvailableLocalizedLabel(locale))) {
        return workbook.createSheet(contentType);
    } else {/* w w  w.j  a  v a 2s.  c om*/
        String sheetName = contentObjectTypeDefinition.getDisplayName().getAvailableLocalizedLabel(locale);

        //Remove invalid characters (according to POI)
        sheetName = StringUtils.replaceChars(sheetName, "/\\?*[]", "");

        //SheetName must be at most 31 chars
        if (sheetName.length() > 31) {
            sheetName = sheetName.substring(0, 30);
        }

        return workbook.createSheet(sheetName);
    }

}

From source file:org.carewebframework.common.StrUtil.java

/**
 * Replaces one set of characters with another. Each character in the <b>from</b> parameter is
 * replaced by the character in the corresponding position in the <b>to</b> parameter. If no
 * corresponding character is present, the character is removed instead.
 * /*from  w  ww . ja v a  2  s. co m*/
 * @param text The string to modify.
 * @param from The list of characters to be replaced.
 * @param to The list of replacement characters.
 * @return The modified input string.
 */
public static String xlate(String text, String from, String to) {
    return StringUtils.replaceChars(text, from, to);
}

From source file:org.dataconservancy.dcs.util.FilePathUtil.java

/**
 * Takes a string path and removes bagit specification blacklisted characters from it, note that path characters are ignored.
 * @param path The path to remove blacklisted characters from
 * @return The sanitized path string with no invalid characters
 *//*from  www. j  a v a2s .  c  o m*/
public static String sanitizePath(String path) {
    //Check for all the characters except path separators
    return StringUtils.replaceChars(path, "<>:\"|?*", null);
}

From source file:org.devproof.portal.core.module.modulemgmt.service.ModuleServiceImpl.java

private String getLocations(ModuleConfiguration config) {
    Set<String> locations = new HashSet<String>();
    for (BoxConfiguration c : config.getBoxes()) {
        locations.add(getLocation(c.getBoxClass()));
    }//from   w  w w  .  ja va2 s  .c o m
    for (Class<?> c : config.getEntities()) {
        locations.add(getLocation(c));
    }
    for (PageConfiguration c : config.getPages()) {
        locations.add(getLocation(c.getPageClass()));
    }
    if (locations.isEmpty()) {
        locations.add("unknown");
    }
    return StringUtils.replaceChars(locations.toString(), "[]", "");
}

From source file:org.docx4j.fonts.BestMatchingMapper.java

private static String generateFontKey(String fontName) {
    return StringUtils.replaceChars(fontName.toLowerCase(), "- ", "");
}

From source file:org.ebayopensource.turmeric.eclipse.codegen.utils.SOACodegenTransformer.java

/**
 * {@inheritDoc}/*w w  w .jav a 2s. c  o m*/
 */
@Override
public BaseCodeGenModel transformModel(IProject project, final IProgressMonitor monitor) throws Exception {
    BaseCodeGenModel model = new BaseCodeGenModel();

    final boolean isConsumerProject = TurmericServiceUtils.isSOAConsumerProject(project);
    if (isConsumerProject) {
        model = new ConsumerCodeGenModel();
    }
    transform(model, project, monitor);

    if (TurmericServiceUtils.isSOAInterfaceProject(project)) {
        final SOAIntfMetadata intfMetadata = SOAIntfUtil
                .loadIntfMetadata(project.getLocation().makeAbsolute().toString(), project.getName());
        final Properties properties = SOAIntfUtil.loadIntfProjectPropFile(project);
        Object obj = properties.get(SOAProjectConstants.PROPS_KEY_NAMESPACE_TO_PACKAGE);
        if (obj != null) {
            final String ns2Pkg = StringUtils.replaceChars(String.valueOf(obj), '|', '=');
            model.setNs2pkg(ns2Pkg);
        }

        transform(model, intfMetadata, monitor);
    } else if (TurmericServiceUtils.isSOAImplProject(project)) {
        final ProjectInfo implProjectInfo = GlobalRepositorySystem.instanceOf().getActiveRepositorySystem()
                .getAssetRegistry().getProjectInfo(project.getName());
        final String serviceName = implProjectInfo.getInterfaceProjectName();
        final SOAImplMetadata implMetadata = SOAImplUtil.loadServiceConfig(project, serviceName);
        final String assetLocation = GlobalRepositorySystem.instanceOf().getActiveRepositorySystem()
                .getAssetRegistry().getAssetLocation(serviceName);

        final SOAIntfMetadata intfMetadata = SOAIntfUtil.loadIntfMetadata(assetLocation, serviceName);
        if (intfMetadata == null)
            throw new CoreException(
                    EclipseMessageUtils.createErrorStatus("Can not load metadata for service->" + serviceName));
        transform(model, intfMetadata, monitor);

        // get the useExternalServiceFactory property value and set it to gen model.
        IFile svcImplProperties = SOAImplUtil.getServiceImplPropertiesFile(project);
        if (svcImplProperties.isAccessible() == true) {
            String useExternalFac = PropertiesFileUtil.getPropertyValueByKey(svcImplProperties.getContents(),
                    SOAProjectConstants.PROPS_KEY_USE_EXTERNAL_SERVICE_FACTORY);
            model.setUseExternalServiceFactory(Boolean.valueOf(useExternalFac));

        }

        model.setServiceImplClassName(implMetadata.getServiceImplClassName());
    }

    if (isConsumerProject) {
        final String clientName = SOAConsumerUtil.getClientName(project);
        ((ConsumerCodeGenModel) model).setClientName(clientName);
        final Map<SOAClientEnvironment, IFile> configFiles = SOAConsumerUtil.getClientConfigFiles(project);
        /*
         * final Set<String> svcNames = new LinkedHashSet<String>(); for
         * (SOAClientEnvironment env : configFiles.keySet()) {
         * svcNames.add(env.getServiceName()); }
         * 
         * final Map<String, String> svcClientMap = SOAConsumerUtil
         * .getMappedServiceNamesFromPropsFile(project, svcNames
         * .toArray(new String[0]));
         */

        for (final SOAClientEnvironment env : configFiles.keySet()) {
            // each service should have a corresponding folder in here
            // using its service name
            final IFile clientConfigFile = configFiles.get(env);
            if (clientConfigFile.isAccessible()) {
                final String serviceName = env.getServiceName();
                final String assetLocation = GlobalRepositorySystem.instanceOf().getActiveRepositorySystem()
                        .getAssetRegistry().getAssetLocation(serviceName);
                final SOAIntfMetadata intfMetadata = SOAIntfUtil.loadIntfMetadata(assetLocation, serviceName);
                if (intfMetadata == null)
                    throw new CoreException(EclipseMessageUtils
                            .createErrorStatus("Can not load metadata for service->" + serviceName));
                final Map<String, String> data = new ConcurrentHashMap<String, String>();
                data.put(BaseCodeGenModel.PARAM_SERVICE_NAME, serviceName);
                data.put(BaseCodeGenModel.PARAM_INTERFACE, intfMetadata.getServiceInterface());
                data.put(BaseCodeGenModel.PARAM_SLAYER, intfMetadata.getServiceLayer());
                data.put(BaseCodeGenModel.PARAM_SCV, intfMetadata.getServiceVersion());
                data.put(BaseCodeGenModel.PARAM_NAMESPACE, intfMetadata.getTargetNamespace());
                data.put(BaseCodeGenModel.PARAM_SL, intfMetadata.getServiceLocation());
                ((ConsumerCodeGenModel) model).getRequiredServices().put(serviceName, data);
            }
        }

    }

    return model;
}

From source file:org.ebayopensource.turmeric.eclipse.errorlibrary.ErrorLibraryActivator.java

/**
 * Gets the image from registry./*from w ww  . ja  v  a2  s . c  o  m*/
 *
 * @param path the path
 * @return the image from registry
 */
public static ImageDescriptor getImageFromRegistry(String path) {
    if (path == null)
        return null;
    path = StringUtils.replaceChars(path, '\\', '/');
    final String iconPath = path.startsWith(ICON_PATH) ? path : ICON_PATH + path;

    ImageDescriptor image = getDefault().getImageRegistry().getDescriptor(iconPath);
    if (image == null) {

        final ImageDescriptor descriptor = imageDescriptorFromPlugin(PLUGIN_ID, iconPath);
        if (descriptor != null) {
            getDefault().getImageRegistry().put(iconPath, descriptor);
            image = getDefault().getImageRegistry().getDescriptor(iconPath);
        }
    }
    return image;
}

From source file:org.ebayopensource.turmeric.eclipse.ui.UIActivator.java

/**
 * Gets the image from registry./*  w w w . j a va  2 s  .co  m*/
 *
 * @param uiPlugin the ui plugin
 * @param iconPathRoot the icon path root
 * @param path the path
 * @return the image from registry
 */
public static Image getImageFromRegistry(AbstractUIPlugin uiPlugin, String iconPathRoot, String path) {
    if (path == null)
        return null;
    path = StringUtils.replaceChars(path, '\\', '/');
    final String iconPath = path.startsWith(iconPathRoot) ? path : iconPathRoot + path;

    Image image = uiPlugin.getImageRegistry().get(iconPath);
    if (image == null) {

        final ImageDescriptor descriptor = imageDescriptorFromPlugin(uiPlugin.getBundle().getSymbolicName(),
                iconPath);
        if (descriptor != null) {
            uiPlugin.getImageRegistry().put(iconPath, descriptor);
            image = uiPlugin.getImageRegistry().get(iconPath);
        }
    }
    return image;

}

From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java

/**
 * Convert class name to file path.//from   w ww.j ava  2 s .c o  m
 *
 * @param className the class name
 * @return the i path
 */
public static IPath convertClassNameToFilePath(String className) {
    if (className == null)
        return null;
    final IPath path = new Path(StringUtils.replaceChars(className, ".", WorkspaceUtil.PATH_SEPERATOR));
    return path.addFileExtension("java");
}