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

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

Introduction

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

Prototype

public static String trim(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null.

Usage

From source file:com.edgenius.wiki.gwt.server.PortalControllerImpl.java

public RenderMarkupModel getDashboard(boolean withMarkup) {
    if (withMarkup) {
        // A big trick! withMarkup is true, means it comes from System page, so do security check here!
        securityDummy.checkInstanceAdmin();
    }/* w  ww . j av a 2s.  c o  m*/

    RenderMarkupModel model = new RenderMarkupModel();
    InstanceSetting instance = settingService.getInstanceSetting();

    if (instance == null || StringUtil.isBlank(instance.getDashboardMarkup()) || StringUtil.equalsIgnoreCase(
            StringUtils.trim(instance.getDashboardMarkup()), SharedConstants.DEFAULT_DAHSBOARD_MARKUP)) {
        //here just handle default directly to MacroModel - for performance reason - most scenario are default 
        //
        MacroModel macro = new MacroModel();
        macro.macroName = SharedConstants.MACRO_PORTAL;
        macro.values.put(NameConstants.SHOWLOGO, Boolean.TRUE.toString());
        model.renderContent.add(macro);
        if (withMarkup) {
            model.markup = SharedConstants.DEFAULT_DAHSBOARD_MARKUP;
        }
    } else {
        if (withMarkup) {
            model.markup = instance.getDashboardMarkup();
        }
        List<RenderPiece> pieces = renderService.renderHTML(instance.getDashboardMarkup());
        model.renderContent.addAll(pieces);
    }
    return model;
}

From source file:com.intuit.tank.report.JobReportOptions.java

public void setJobIdEnd(String jobIdEnd) {
    this.jobIdEnd = StringUtils.trim(jobIdEnd);
}

From source file:info.magnolia.rendering.template.configured.ConfiguredInheritance.java

@Override
public AbstractPredicate<Node> getComponentPredicate() {
    if (isEnabled() == null || !isEnabled()) {
        return new InheritNothingInheritancePredicate();
    }/*  w  ww .j a v a 2 s . c  o m*/
    if (predicateClass != null) {
        return Components.newInstance(predicateClass);
    }
    if (StringUtils.equalsIgnoreCase(StringUtils.trim(components), COMPONENTS_ALL)) {
        return new AllComponentsAndResourcesInheritancePredicate();
    }
    if (StringUtils.equalsIgnoreCase(StringUtils.trim(components), COMPONENTS_FILTERED)) {
        return new FilteredComponentInheritancePredicate();
    }
    return new InheritNothingInheritancePredicate();
}

From source file:com.smartitengineering.util.bean.guice.GuiceUtil.java

private GuiceUtil(Properties properties) {
    String contextNameProp = properties.getProperty(CONTEXT_NAME_PROP);
    if (StringUtils.isBlank(contextNameProp)) {
        throw new IllegalStateException("Bean factory context name can not be blank");
    }//from   ww  w  . ja  va2 s.  com
    contextNames = contextNameProp.split(",");
    ignoreMissingDependency = Boolean.parseBoolean(properties.getProperty(IGNORE_MISSING_DEP_PROP));
    final String[] moduleStrs;
    List<String> moduleConfigs = new ArrayList<String>();
    for (Entry<Object, Object> entry : properties.entrySet()) {
        if (entry.getKey().toString().startsWith(MODULES_LIST_PROP)) {
            moduleConfigs.add(entry.getValue().toString());
        }
    }
    moduleStrs = new String[moduleConfigs.size()];
    moduleConfigs.toArray(moduleStrs);
    modules = new List[moduleStrs.length];
    int index = 0;
    for (String modulesStr : moduleStrs) {
        if (StringUtils.isBlank(modulesStr)) {
            throw new IllegalStateException("Modules must be specified in a comma separated list!");
        }
        String[] moduleClassNames = modulesStr.split(",");
        List<Module> moduleSet = new ArrayList<Module>(moduleClassNames.length);
        for (String moduleClassName : moduleClassNames) {
            final Class clazz;
            try {
                clazz = Class.forName(StringUtils.trim(moduleClassName), true,
                        Thread.currentThread().getContextClassLoader());
            } catch (ClassNotFoundException ex) {
                throw new IllegalStateException(ex);
            }
            if (!Module.class.isAssignableFrom(clazz)) {
                throw new IllegalArgumentException("Specified class not instance of Module");
            }
            Class<? extends Module> moduleClass = clazz;
            boolean foundConstructor = false;
            try {
                Constructor<? extends Module> defaultContructor = moduleClass.getConstructor();
                moduleSet.add(defaultContructor.newInstance());
                foundConstructor = true;
            } catch (InstantiationException ex) {
                throw new IllegalStateException(ex);
            } catch (IllegalAccessException ex) {
                throw new IllegalStateException(ex);
            } catch (InvocationTargetException ex) {
                throw new IllegalStateException(ex);
            } catch (NoSuchMethodException ex) {
            } catch (SecurityException ex) {
            }
            if (!foundConstructor) {
                try {
                    Constructor<? extends Module> defaultContructor = moduleClass
                            .getConstructor(Properties.class);
                    moduleSet.add(defaultContructor.newInstance(properties));
                    foundConstructor = true;
                } catch (InstantiationException ex) {
                    throw new IllegalStateException(ex);
                } catch (IllegalAccessException ex) {
                    throw new IllegalStateException(ex);
                } catch (InvocationTargetException ex) {
                    throw new IllegalStateException(ex);
                } catch (NoSuchMethodException ex) {
                } catch (SecurityException ex) {
                }
            }
            if (!foundConstructor) {
                throw new IllegalStateException(
                        "No supported contructors found - no args and with a properties obj!");
            }
        }
        modules[index++] = moduleSet;
    }
}

From source file:cn.shengyuan.yun.admin.web.template.directive.BaseDirective.java

/**
 * ??//from   www. j  a  va  2 s.co m
 * 
 * @param params
 *            ?
 * @param ignoreProperties
 *            
 * @return ?
 */
protected List<Order> getOrders(Map<String, TemplateModel> params, String... ignoreProperties)
        throws TemplateModelException {
    String orderBy = StringUtils
            .trim(FreemarkerUtils.getParameter(ORDER_BY_PARAMETER_NAME, String.class, params));
    List<Order> orders = new ArrayList<Order>();
    if (StringUtils.isNotEmpty(orderBy)) {
        String[] orderByItems = orderBy.split(ORDER_BY_ITEM_SEPARATOR);
        for (String orderByItem : orderByItems) {
            if (StringUtils.isNotEmpty(orderByItem)) {
                String property = null;
                Direction direction = null;
                String[] orderBys = orderByItem.split(ORDER_BY_FIELD_SEPARATOR);
                if (orderBys.length == 1) {
                    property = orderBys[0];
                } else if (orderBys.length >= 2) {
                    property = orderBys[0];
                    try {
                        direction = Direction.valueOf(orderBys[1]);
                    } catch (IllegalArgumentException e) {
                        continue;
                    }
                } else {
                    continue;
                }
                if (!ArrayUtils.contains(ignoreProperties, property)) {
                    orders.add(new Order(property, direction));
                }
            }
        }
    }
    return orders;
}

From source file:com.flexive.shared.media.FxMimeTypeWrapper.java

/**
 * Add a mime type by providing a String parameter
 * The parameter can either be a single mime type or a list of comma-separated values
 *
 * @param mimeTypes the mime type as a String, e.g. "audio/wav", or several values such as "audio/wav,audio/mp3"
 *///  w  w  w  .  java 2s.c  o  m
public void addMimeTypes(String mimeTypes) {
    String[] mtSplit = mimeTypes.split(",");
    for (String m : mtSplit) {
        m = StringUtils.trim(m);
        final FxMimeType mt = FxMimeType.getMimeType(m);
        if (!this.mimeTypes.contains(mt))
            this.mimeTypes.add(mt);
    }
}

From source file:eu.europeana.corelib.search.utils.SearchUtils.java

public static String escapeFacet(String field, String query) {
    if (StringUtils.isNotBlank(field) && StringUtils.isNotBlank(query)) {
        query = escapeQuery(StringUtils.trim(query));
        return StringUtils.trim(field) + ":\"" + query + "\"";
    }/*from  w  ww.  j av  a2  s  .  co  m*/
    return null;
}

From source file:com.adobe.acs.tools.csv_asset_importer.impl.Column.java

protected <T> T toObjectType(String data, Class<T> klass) {
    data = StringUtils.trim(data);

    if (Double.class.equals(klass)) {
        try {//from   www  . j av  a  2  s  . co  m
            return klass.cast(Double.parseDouble(data));
        } catch (NumberFormatException ex) {
            return null;
        }
    } else if (Long.class.equals(klass)) {
        try {
            return klass.cast(Long.parseLong(data));
        } catch (NumberFormatException ex) {
            return null;
        }
    } else if (Integer.class.equals(klass)) {
        try {
            return klass.cast(Long.parseLong(data));
        } catch (NumberFormatException ex) {
            return null;
        }
    } else if (StringUtils.equalsIgnoreCase("true", data) && Boolean.class.equals(klass)) {
        return klass.cast(Boolean.TRUE);
    } else if (StringUtils.equalsIgnoreCase("false", data) && Boolean.class.equals(klass)) {
        return klass.cast(Boolean.FALSE);
    } else if (Date.class.equals(klass) || Calendar.class.equals(klass)) {
        return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toCalendar(Locale.US));
    } else {
        return klass.cast(data);
    }
}

From source file:eu.markov.jenkins.plugin.mvnmeta.MavenMetadataParameterDefinition.java

@DataBoundConstructor
public MavenMetadataParameterDefinition(String name, String description, String repoBaseUrl, String groupId,
        String artifactId, String packaging, String versionFilter, String sortOrder, String defaultValue,
        String maxVersions, String username, String password) {
    super(name, description);
    this.repoBaseUrl = Util.removeTrailingSlash(repoBaseUrl);
    this.groupId = groupId;
    this.artifactId = artifactId;
    this.packaging = packaging;
    this.versionFilter = StringUtils.trim(versionFilter);
    this.sortOrder = SortOrder.valueOf(sortOrder);
    this.defaultValue = StringUtils.trim(defaultValue);
    this.maxVersions = maxVersions;
    this.username = username;
    this.password = password;
}

From source file:com.taobao.tdhs.jdbc.util.StringUtil.java

public static String[] escapeIn(String value) {
    value = StringUtils.trim(value);
    if (!StringUtils.startsWith(value, "(") || !StringUtils.endsWith(value, ")")) {
        return null;
    }/*from   w w w .  jav  a 2s  .com*/
    value = value.substring(1, value.length() - 1);
    String[] split = StringUtils.split(value, ",");
    String[] result = new String[split.length];
    int i = 0;
    for (String s : split) {
        String str = escapeValue(s);
        if (StringUtils.isBlank(str)) {
            return null;
        }
        result[i++] = str;
    }
    return result;
}