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

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

Introduction

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

Prototype

public static String strip(String str, String stripChars) 

Source Link

Document

Strips any of a set of characters from the start and end of a String.

Usage

From source file:org.eclipse.uomo.util.impl.Iso8601Date.java

private String checkSections(String content, String whole, String mask) {
    String workingMask = StringUtils.strip(mask, Messages.Iso8601Date_63);
    String[] parts = { "", workingMask }; //$NON-NLS-1$
    boolean first = true;
    inFraction = false;//  w  ww .j ava 2  s. c o  m

    do {
        parts = StringUtils.splitPreserveAllTokens(parts[1], Messages.Iso8601Date_65, 2);
        String token = parts[0];
        if (token != null) { // support use of [ at first point to make
                             // everything optional
            String section = content == null || content.length() < token.length() ? null
                    : content.substring(0, token.length()); // sSection =
            // copy(sContent, 1,
            // length(sToken));
            if (section == null) { // if sSection = '' then
                if (!first) {
                    if (content != null && content.length() < token.length())
                        return Messages.Iso8601Date_66 + content + Messages.Iso8601Date_67 + token;
                    else
                        return Messages.Iso8601Date_68 + token + Messages.Iso8601Date_69 + mask
                                + Messages.Iso8601Date_70 + whole;
                }
            } else if (section.length() < token.length()) {
                return Messages.Iso8601Date_71 + token + Messages.Iso8601Date_72 + mask
                        + Messages.Iso8601Date_73 + whole + Messages.Iso8601Date_74 + section;
            } else {
                String error = checkSection(token, section);
                if (error != null)
                    return error;
                else if (section.length() >= content.length())
                    content = null;
                else
                    content = content.substring(section.length());
            }
        }
        first = false;
    } while (parts.length > 1 && content != null); // until not result or
    // (sFormat = '') or
    // (sContent = '');
    if (content != null) {
        return Messages.Iso8601Date_75 + content + Messages.Iso8601Date_76 + whole + Messages.Iso8601Date_77
                + mask;
    } else
        return null;
}

From source file:org.eclipse.wb.internal.swing.MigLayout.model.MigDimensionInfo.java

/**
 * @param withBraces/*from   w  w w .j  a va2  s  .c o  m*/
 *          is <code>true</code>, if surrounding <code>[]</code> should be used.
 * 
 * @return the constraints of this {@link MigDimensionInfo} as string.
 */
public final String getString(boolean withBraces) {
    AC ac = new AC();
    ac.setConstaints(new DimConstraint[] { m_constraint });
    String constraintString = IDEUtil.getConstraintString(ac, false, m_horizontal);
    if (!withBraces) {
        constraintString = StringUtils.strip(constraintString, "[]");
    }
    return constraintString;
}

From source file:org.eclipse.wb.internal.swing.MigLayout.model.MigDimensionInfo.java

/**
 * @return the string presentation of given {@link BoundSize}.
 *//*from   ww w.  j  av a  2  s.  co m*/
public final String getString(BoundSize boundSize) {
    if (boundSize != null) {
        AC ac = new AC();
        DimConstraint dimConstraint = new DimConstraint();
        dimConstraint.setSize(boundSize);
        ac.setConstaints(new DimConstraint[] { dimConstraint });
        String constraintString = IDEUtil.getConstraintString(ac, false, m_horizontal);
        return StringUtils.strip(constraintString, "[]");
    } else {
        return null;
    }
}

From source file:org.fracturedatlas.athena.audit.manager.AuditManager.java

static Set<String> parseValues(String valueString) {
    HashSet<String> values = new HashSet<String>();
    valueString = StringUtils.trimToEmpty(valueString);
    valueString = StringUtils.strip(valueString, "()");
    valueString = StringUtils.trimToEmpty(valueString);
    CharacterIterator it = new StringCharacterIterator(valueString);
    boolean inString = false;
    int begin = 0;
    int end = 0;//from w  ww. j  av  a2  s.  c  om
    int numValues = 0;
    StringBuilder sb = new StringBuilder();
    // Iterate over the characters in the forward direction
    for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
        if (ch == '\"') {
            inString = true;
            ch = it.next();
            sb = new StringBuilder();
            for (; ch != CharacterIterator.DONE; ch = it.next()) {
                if (ch == '\\') {
                    // skip any " in a string
                    sb.append(ch);
                    ch = it.next();
                } else if (ch == '\"') {
                    break;
                }
                sb.append(ch);
            }
            inString = false;
            values.add(StringUtils.trimToEmpty(sb.toString()));
        } else if (ch == ',') {
            // new value
        } else if (" \t\n\r".indexOf(ch) > -1) {
            //skip whitespace
        } else {
            // not a comma, whitespace or a string start
            sb = new StringBuilder();
            for (; ch != CharacterIterator.DONE; ch = it.next()) {
                if (ch == ',') {
                    break;
                }
                sb.append(ch);
            }
            inString = false;
            values.add(StringUtils.trimToEmpty(sb.toString()));

        }
    }
    return values;
}

From source file:org.fracturedatlas.athena.search.AthenaSearch.java

public static Set<String> parseValues(String valueString) {
    HashSet<String> values = new HashSet<String>();
    valueString = StringUtils.trimToEmpty(valueString);
    valueString = StringUtils.strip(valueString, "()");
    valueString = StringUtils.trimToEmpty(valueString);
    CharacterIterator it = new StringCharacterIterator(valueString);
    boolean inString = false;
    int begin = 0;
    int end = 0;// w  w  w  . jav a2 s .  c o  m
    int numValues = 0;
    StringBuilder sb = new StringBuilder();
    // Iterate over the characters in the forward direction
    for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
        if (ch == '\"') {
            inString = true;
            ch = it.next();
            sb = new StringBuilder();
            for (; ch != CharacterIterator.DONE; ch = it.next()) {
                if (ch == '\\') {
                    // skip any " in a string
                    sb.append(ch);
                    ch = it.next();
                } else if (ch == '\"') {
                    break;
                }
                sb.append(ch);
            }
            inString = false;
            values.add(StringUtils.trimToEmpty(sb.toString()));
        } else if (ch == ',') {
            // new value
        } else if (" \t\n\r".indexOf(ch) > -1) {
            //skip whitespace
        } else {
            // not a comma, whitespace or a string start
            sb = new StringBuilder();
            for (; ch != CharacterIterator.DONE; ch = it.next()) {
                if (ch == ',') {
                    break;
                }
                sb.append(ch);
            }
            inString = false;
            values.add(StringUtils.trimToEmpty(sb.toString()));

        }
    }

    return values;
}

From source file:org.fracturedatlas.athena.web.manager.RecordManager.java

static Set<String> parseValues(String valueString) {
    HashSet<String> values = new HashSet<String>();
    valueString = StringUtils.trimToEmpty(valueString);
    valueString = StringUtils.strip(valueString, "()");
    valueString = StringUtils.trimToEmpty(valueString);
    CharacterIterator it = new StringCharacterIterator(valueString);
    boolean inString = false;
    int begin = 0;
    int end = 0;/*  ww  w  .jav a2s  .  com*/
    int numValues = 0;
    StringBuilder sb = new StringBuilder();
    // Iterate over the characters in the forward direction
    for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
        if (ch == '\"') {
            inString = true;
            ch = it.next();
            sb = new StringBuilder();
            for (; ch != CharacterIterator.DONE; ch = it.next()) {
                if (ch == '\\') {
                    // skip any " in a string
                    sb.append(ch);
                    ch = it.next();
                } else if (ch == '\"') {
                    break;
                }
                sb.append(ch);
            }
            inString = false;
            values.add(StringUtils.trimToEmpty(sb.toString()));
        } else if (ch == ',') {
            // new value
        } else if (" \t\n\r".indexOf(ch) > -1) {
            //skip whitespace
        } else {
            // not a comma, whitespace or a string start
            sb = new StringBuilder();
            for (; ch != CharacterIterator.DONE; ch = it.next()) {
                if (ch == ',') {
                    break;
                }
                sb.append(ch);
            }
            inString = false;
            values.add(StringUtils.trimToEmpty(sb.toString()));

        }
    }

    return values;
}

From source file:org.geoserver.taskmanager.external.impl.PostgisDialectImpl.java

@Override
public Set<String> getSpatialColumns(Connection sourceConn, String tableName, String defaultSchema) {
    String schema = StringUtils.strip(SqlUtil.schema(tableName), "\"");
    String unqualifiedTableName = StringUtils.strip(SqlUtil.notQualified(tableName), "\"");

    if (schema == null) {
        schema = defaultSchema == null ? "public" : defaultSchema;
    }// ww  w.  jav a  2s  . c  o  m

    HashSet<String> spatialColumns = new HashSet<>();
    try (Statement stmt = sourceConn.createStatement()) {
        try (ResultSet rs = stmt
                .executeQuery("SELECT * FROM geometry_columns " + " WHERE geometry_columns.f_table_name='"
                        + unqualifiedTableName + "' and f_table_schema = '" + schema + "' ")) {
            while (rs.next()) {
                spatialColumns.add(rs.getString("f_geometry_column"));
            }
        }
    } catch (SQLException e) {
        LOGGER.severe("Could not find the spatial columns:" + e.getMessage());
    }

    return spatialColumns;
}

From source file:org.geoserver.taskmanager.tasks.CopyTableTaskTypeImpl.java

private static String getSchema(Connection conn, String tableName) throws SQLException {
    String schema = StringUtils.strip(SqlUtil.schema(tableName), "\"");
    if (conn.getMetaData().storesUpperCaseIdentifiers()) {
        schema = schema.toUpperCase();/*from w  w w. j  a  v a  2  s .c o m*/
    } else if (conn.getMetaData().storesUpperCaseIdentifiers()) {
        schema = schema.toLowerCase();
    }
    return schema;
}

From source file:org.intermine.webservice.server.lists.AvailableListsService.java

protected Collection<InterMineBag> getListsMatching(ListManager listManager, String nameFilter) {
    if (nameFilter == null) {
        throw new IllegalArgumentException("nameFilter must not be null");
    }/*from  ww w  .  j a va 2 s.  co  m*/

    nameFilter = nameFilter.trim();
    final Filter type = getFilterType(nameFilter);
    final String term = StringUtils.strip(nameFilter, "*");

    Set<InterMineBag> ret = new LinkedHashSet<InterMineBag>();
    for (InterMineBag bag : listManager.getLists()) {
        boolean suitable = false;
        if (bag != null) {
            String bagName = StringUtils.defaultString(bag.getName(), "");
            switch (type) {
            case EXACT:
                suitable = term.equals(bagName);
                break;
            case PREFIX:
                suitable = bagName.startsWith(term);
                break;
            case SUFFIX:
                suitable = bagName.endsWith(term);
                break;
            case CONTAINS:
                suitable = bagName.contains(term);
                break;
            }
        }
        if (suitable) {
            ret.add(bag);
        }
    }
    if (ret.isEmpty()) {
        throw new ResourceNotFoundException("No lists matched " + nameFilter);
    }
    return ret;
}

From source file:org.jahia.modules.external.modules.ModulesDataSource.java

private synchronized void savePropertyDefinition(ExternalData data) throws RepositoryException {
    String path = data.getPath();
    String pathLowerCase = path.toLowerCase();
    String cndPath = getCndPath(path, pathLowerCase);
    String subPath = getSubPath(path, pathLowerCase);
    String[] splitPath = StringUtils.split(subPath, "/");

    NodeTypeRegistry nodeTypeRegistry = loadRegistry(cndPath);
    String nodeTypeName = splitPath[0];
    nodeTypeName = nodeTypeName.replace('-', '_');
    String lastPathSegment = splitPath[1];
    try {/* w  ww  .  j  av  a2 s.  c  o m*/
        ExtendedNodeType nodeType = nodeTypeRegistry.getNodeType(nodeTypeName);
        boolean unstructured = "jnt:unstructuredPropertyDefinition".equals(data.getType());
        ExtendedPropertyDefinition propertyDefinition;
        if (unstructured) {
            Integer key = Integer.valueOf(StringUtils.substringAfter(lastPathSegment, UNSTRUCTURED_PROPERTY));
            propertyDefinition = nodeType.getDeclaredUnstructuredPropertyDefinitions().get(key);
        } else {
            propertyDefinition = nodeType.getDeclaredPropertyDefinitionsAsMap().get(lastPathSegment);
        }
        if (propertyDefinition == null) {
            propertyDefinition = new ExtendedPropertyDefinition(nodeTypeRegistry);
            String qualifiedName = unstructured ? "*" : lastPathSegment;
            Name name = new Name(qualifiedName, nodeTypeRegistry.getNamespaces());
            propertyDefinition.setName(name);
            propertyDefinition
                    .setRequiredType(PropertyType.valueFromName(data.getProperties().get(J_REQUIRED_TYPE)[0]));
            String[] isMultiple = data.getProperties().get(J_MULTIPLE);
            if (isMultiple != null && isMultiple.length > 0) {
                propertyDefinition.setMultiple(Boolean.parseBoolean(isMultiple[0]));
            }
            propertyDefinition.setDeclaringNodeType(nodeType);
        }
        Map<String, String[]> properties = data.getProperties();
        String[] values = properties.get(J_AUTO_CREATED);
        if (values != null && values.length > 0) {
            propertyDefinition.setAutoCreated(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setAutoCreated(false);
        }
        values = properties.get(J_MANDATORY);
        if (values != null && values.length > 0) {
            propertyDefinition.setMandatory(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setMandatory(false);
        }
        values = properties.get(J_ON_PARENT_VERSION);
        if (values != null && values.length > 0) {
            propertyDefinition.setOnParentVersion(OnParentVersionAction.valueFromName(values[0]));
        } else {
            propertyDefinition.setOnParentVersion(OnParentVersionAction.VERSION);
        }
        values = properties.get(J_PROTECTED);
        if (values != null && values.length > 0) {
            propertyDefinition.setProtected(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setProtected(false);
        }
        values = properties.get(J_SELECTOR_TYPE);
        int selectorType = SelectorType.SMALLTEXT; // Default selector type is smallText
        if (values != null && values.length > 0) {
            selectorType = SelectorType.valueFromName(values[0]);
        } else if (propertyDefinition.getRequiredType() == PropertyType.WEAKREFERENCE) {
            selectorType = SelectorType.CONTENTPICKER;
        } else if (propertyDefinition.getRequiredType() == PropertyType.DATE) {
            selectorType = SelectorType.DATETIMEPICKER;
        }
        propertyDefinition.setSelector(selectorType);
        values = properties.get(J_SELECTOR_OPTIONS);
        Map<String, String> selectorOptions = new HashMap<String, String>();
        if (values != null) {
            for (String option : values) {
                String[] keyValue = StringUtils.split(option, "=", 3);
                if (keyValue.length > 1) {
                    selectorOptions.put(keyValue[0].trim(), StringUtils.strip(keyValue[1].trim(), "'"));
                } else {
                    selectorOptions.put(keyValue[0].trim(), "");
                }
            }
        }
        propertyDefinition.setSelectorOptions(selectorOptions);
        values = properties.get(J_REQUIRED_TYPE);
        int requiredType = 0;
        if (values != null && values.length > 0) {
            requiredType = PropertyType.valueFromName(values[0]);
        }
        propertyDefinition.setRequiredType(requiredType);
        values = properties.get(J_VALUE_CONSTRAINTS);
        List<Value> valueConstraints = new ArrayList<Value>();
        if (values != null) {
            for (String valueConstraint : values) {
                valueConstraints.add(getValueFromString(valueConstraint, requiredType, true));
            }
        }
        propertyDefinition.setValueConstraints(valueConstraints.toArray(new Value[valueConstraints.size()]));
        values = properties.get(J_DEFAULT_VALUES);
        List<Value> defaultValues = new ArrayList<Value>();
        if (values != null) {
            for (String defaultValue : values) {
                defaultValues.add(getValueFromString(defaultValue, requiredType, false));
            }
        }
        propertyDefinition.setDefaultValues(defaultValues.toArray(new Value[defaultValues.size()]));
        values = properties.get(J_MULTIPLE);
        if (values != null && values.length > 0) {
            propertyDefinition.setMultiple(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setMultiple(false);
        }
        values = properties.get(J_AVAILABLE_QUERY_OPERATORS);
        List<String> ops = new ArrayList<String>();
        if (values != null) {
            for (String op : values) {
                if (op.equals(Lexer.QUEROPS_EQUAL)) {
                    ops.add(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO);
                } else if (op.equals(Lexer.QUEROPS_NOTEQUAL)) {
                    ops.add(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO);
                } else if (op.equals(Lexer.QUEROPS_LESSTHAN)) {
                    ops.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN);
                } else if (op.equals(Lexer.QUEROPS_LESSTHANOREQUAL)) {
                    ops.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO);
                } else if (op.equals(Lexer.QUEROPS_GREATERTHAN)) {
                    ops.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN);
                } else if (op.equals(Lexer.QUEROPS_GREATERTHANOREQUAL)) {
                    ops.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO);
                } else if (op.equals(Lexer.QUEROPS_LIKE)) {
                    ops.add(QueryObjectModelConstants.JCR_OPERATOR_LIKE);
                }
            }
        }
        if (ops.isEmpty()) {
            propertyDefinition.setAvailableQueryOperators(Lexer.ALL_OPERATORS);
        } else {
            propertyDefinition.setAvailableQueryOperators(ops.toArray(new String[ops.size()]));
        }
        values = properties.get(J_IS_FULL_TEXT_SEARCHABLE);
        if (values != null && values.length > 0) {
            propertyDefinition.setFullTextSearchable(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setFullTextSearchable(true);
        }
        values = properties.get(J_IS_QUERY_ORDERABLE);
        if (values != null && values.length > 0) {
            propertyDefinition.setQueryOrderable(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setQueryOrderable(true);
        }
        values = properties.get(J_IS_FACETABLE);
        if (values != null && values.length > 0) {
            propertyDefinition.setFacetable(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setFacetable(false);
        }
        values = properties.get(J_IS_HIERARCHICAL);
        if (values != null && values.length > 0) {
            propertyDefinition.setHierarchical(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setHierarchical(false);
        }
        values = properties.get(J_IS_INTERNATIONALIZED);
        if (values != null && values.length > 0) {
            propertyDefinition.setInternationalized(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setInternationalized(false);
        }
        values = properties.get(J_IS_HIDDEN);
        if (values != null && values.length > 0) {
            propertyDefinition.setHidden(Boolean.parseBoolean(values[0]));
        } else {
            propertyDefinition.setHidden(false);
        }
        values = properties.get(J_INDEX);
        if (values != null && values.length > 0) {
            propertyDefinition.setIndex(IndexType.valueFromName(values[0].toLowerCase()));
        } else {
            propertyDefinition.setIndex(IndexType.TOKENIZED);
        }
        values = properties.get(J_SCOREBOOST);
        if (values != null && values.length > 0) {
            propertyDefinition.setScoreboost(Double.parseDouble(values[0]));
        } else {
            propertyDefinition.setScoreboost(1.);
        }
        values = properties.get(J_ANALYZER);
        if (values != null && values.length > 0) {
            propertyDefinition.setAnalyzer(values[0]);
        } else {
            propertyDefinition.setAnalyzer(null);
        }
        values = properties.get(J_ON_CONFLICT_ACTION);
        if (values != null && values.length > 0) {
            propertyDefinition.setOnConflict(OnConflictAction.valueFromName(values[0]));
        } else {
            propertyDefinition.setOnConflict(OnConflictAction.USE_LATEST);
        }
        values = properties.get(J_ITEM_TYPE);
        if (values != null && values.length > 0) {
            propertyDefinition.setItemType(values[0]);
        } else {
            propertyDefinition.setItemType(null);
        }
        nodeType.validate();
        writeDefinitionFile(nodeTypeRegistry, cndPath);

        saveCndResourceBundle(data, JCRContentUtils.replaceColon(nodeTypeName) + "."
                + JCRContentUtils.replaceColon(lastPathSegment));
    } catch (NoSuchNodeTypeException e) {
        removeNodeTypeRegistry(cndPath);
        throw e;
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}