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

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

Introduction

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

Prototype

public static String substringBefore(String str, String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:org.eclipse.wb.internal.swing.databinding.ui.contentproviders.DetailBindingUiContentProvider.java

public void updateFromObject() throws Exception {
    String elementClassName = m_binding.getJListBinding().getInputElementType().getFullTypeName();
    setClassNameAndProperty(StringUtils.substringBefore(elementClassName, "<")
            + StringUtils.substringAfterLast(elementClassName, ">"), m_binding.getDetailProperty());
}

From source file:org.eclipse.wb.internal.swing.model.component.JTabbedPaneAtAccessor.java

@Override
public boolean setExpression(JavaInfo javaInfo, String source) throws Exception {
    MethodInvocation invocation = getMethodInvocation();
    if (invocation != null) {
        boolean remove = source == null || source.equals(m_defaultSource);
        if (remove) {
            javaInfo.startEdit();/*from  w  w  w .j a  va  2s  . com*/
            try {
                m_pane.getEditor().removeEnclosingStatement(invocation);
            } finally {
                javaInfo.endEdit();
            }
        } else {
            Expression oldExpression = (Expression) invocation.arguments().get(1);
            if (!javaInfo.getEditor().getSource(oldExpression).equals(source)) {
                javaInfo.startEdit();
                try {
                    javaInfo.getEditor().replaceExpression(oldExpression, source);
                } finally {
                    javaInfo.endEdit();
                }
            }
        }
    } else if (source != null) {
        javaInfo.startEdit();
        try {
            // prepare invocation source
            String invocationSource;
            {
                String methodName = StringUtils.substringBefore(m_signature, "(");
                int componentIndex = getComponentIndex();
                invocationSource = TemplateUtils.format("{0}.{1}({2}, {3})", m_pane, methodName, componentIndex,
                        source);
            }
            // prepare target
            StatementTarget target = getAtTarget(m_component);
            // add invocation
            Expression expression = m_pane.addExpressionStatement(target, invocationSource);
            m_component.addRelatedNode(expression);
        } finally {
            javaInfo.endEdit();
        }
    }
    // success
    return true;
}

From source file:org.eclipse.wb.internal.swt.model.property.editor.image.plugin.WorkspacePluginInfo.java

/**
 * @return <i>bundle symbolic name</i> for given project or <code>null</code> if project is't
 *         plugin./*from www.  j  a va  2s .  c  o m*/
 */
public static String getBundleSymbolicName(IProject project) {
    // handle META-INF/MANIFEST.MF
    try {
        IFile manifestFile = project.getFile(MANIFEST_PATH);
        if (manifestFile.exists()) {
            Map<String, String> manifest = parseBundleManifest(manifestFile);
            String bundleSymbolicName = manifest.get("Bundle-SymbolicName");
            if (!StringUtils.isEmpty(bundleSymbolicName)) {
                bundleSymbolicName = StringUtils.substringBefore(bundleSymbolicName, ";").trim();
                if (!StringUtils.isEmpty(bundleSymbolicName)) {
                    return bundleSymbolicName;
                }
            }
        }
    } catch (Exception e) {
    }
    // handle plugin.xml
    try {
        IFile pluginFile = project.getFile(MANIFEST_PATH);
        if (pluginFile.exists()) {
            DocumentElement pluginNode = parsePluginXml(pluginFile);
            if ("plugin".equalsIgnoreCase(pluginNode.getTag())) {
                String bundleSymbolicName = pluginNode.getAttribute("id");
                if (!StringUtils.isEmpty(bundleSymbolicName)) {
                    return bundleSymbolicName;
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:org.eclipse.wb.tests.gef.UiContext.java

/**
 * Normalizes given {@link String} by removing special characters.
 *//*w w  w  . java 2  s.c  o m*/
private static String normalizeTextForComparing(String s) {
    s = s.trim();
    s = StringUtils.remove(s, '&');
    s = StringUtils.substringBefore(s, "\t");
    return s;
}

From source file:org.ednovo.gooru.application.util.GooruImageUtil.java

public static String getFileExtenstion(String filePath) {
    if (filePath != null) {
        if (filePath.contains("?")) {
            filePath = StringUtils.substringBefore(filePath, "?");
        }/*  www. j a va2  s . c  o  m*/
        return StringUtils.substringAfterLast(filePath, ".");
    } else {
        return null;
    }
}

From source file:org.ednovo.gooru.application.util.GooruImageUtil.java

public static String getFileName(String filePath) {
    if (filePath != null) {
        if (filePath.contains("?")) {
            filePath = StringUtils.substringBefore(filePath, "?");
        }/*  w w w  . ja v  a2 s .c  om*/
        return StringUtils.substringAfterLast(filePath, "/");
    } else {
        return null;
    }
}

From source file:org.ednovo.gooru.application.util.GooruImageUtil.java

public static String getFileNamePrefix(String filePath) {
    if (filePath != null) {
        if (filePath.contains("/")) {
            filePath = StringUtils.substringAfterLast(filePath, "/");
        }// w ww  .j a  v a 2s.  c  o m
        if (filePath.contains("?")) {
            filePath = StringUtils.substringBefore(filePath, "?");
        }
        return StringUtils.substringBeforeLast(filePath, ".");
    } else {
        return null;
    }

}

From source file:org.endiansummer.tools.soaprunner.VariableStore.java

public String getVariable(String key) {

    String idxStr = StringUtils.substringBetween(key, "[", "]");
    if (idxStr != null) {
        key = StringUtils.substringBefore(key, "[").trim();
        idxStr = idxStr.trim();/* www .  j av  a  2  s . c o  m*/
    }

    int index = idxStr != null ? Integer.parseInt(idxStr) : getVariableCount(key) - 1;
    return getVariable(key, index);
}

From source file:org.entando.edo.parser.FieldsParser.java

public String[] parse(EdoBean edoBean, String[] args) throws Exception {
    _logger.trace("input params: {}", Arrays.toString(args));
    List<EdoField> fieldsList = new ArrayList<EdoField>();
    List<String> fieldNames = new ArrayList<String>();
    int index = 0;
    for (int i = 0; i < args.length; i++) {
        String param = args[i];/* w  w w  . j a v a 2  s.  c  om*/
        if (this.isFieldArg(param)) {
            index = i;
            _logger.trace("the param: '{}' has a valid pattern", param);
            if (this.isValidField(param)) {
                _logger.trace("the field {} is valid field", param);
                EdoField edoField = new EdoField();
                String[] p = param.split(":");
                String fieldName = p[0];
                String fieldType = p[1];
                String fieldDataType = StringUtils.substringBefore(fieldType, "-").toLowerCase();
                String fieldFlags = StringUtils.substringAfter(fieldType, "-");
                edoField.setName(fieldName);
                edoField.setType(DataTypeManager.getInstance().getDataTypes().get(fieldDataType));

                if (i > 0 && fieldDataType.equalsIgnoreCase(DataTypeManager.TYPE_PRIMARY_KEY)) {
                    throw new Exception("error parsing fields: the primary key must be the first field");
                }

                if (i == 0) {
                    if (fieldDataType.equalsIgnoreCase(DataTypeManager.TYPE_PRIMARY_KEY)) {
                        edoField.setRequired(true);
                        edoField.setPrimaryKey(true);
                    } else {
                        this.addDefaulPkFileld(fieldsList, fieldNames);
                    }
                }

                edoField.setRequired(fieldFlags.contains("r"));

                Pattern pattern = Pattern.compile("(\\D*)(\\d+)(\\D*)");
                Matcher matcher = pattern.matcher(fieldFlags);
                if (matcher.matches()) {
                    if (!edoField.getType().getJavaType().equals("String")) {
                        _logger.warn("length option is valid only for string fields! -- skipping...");
                    } else {
                        String len = matcher.group(2);
                        if (StringUtils.isNumeric(len)) {
                            edoField.setLength(new Integer(len));
                        }
                    }
                }
                if (fieldsList.isEmpty() && edoField.getType().getJavaType().equals("BigDecimal")) {
                    throw new Exception("BigDecimal cannot be used as primary key");
                }
                if (!fieldNames.contains(edoField.getName())) {
                    fieldsList.add(edoField);
                    fieldNames.add(edoField.getName());
                    _logger.debug("added field with name '{}' and type {} ", edoField.getName(),
                            edoField.getType().getJavaType());
                } else {
                    _logger.error("field '{}' is already present", edoField.getName());
                    if (edoField.getName().equalsIgnoreCase("id") && fieldsList.get(0).getType()
                            .equals(DataTypeManager.getInstance().getDataTypes().get("primary_key"))) {
                        _logger.error(
                                "remember that if you do not specify a field of type :primary_key, an implicit field id:int is autamatically generated as primary key");
                    }
                    throw new Exception("error parsing fields");
                }
            } else {
                _logger.error("'{}' is not a valid field", param);
                throw new Exception("error parsing fields");
            }
        } else {
            _logger.debug("the param '{}' is not valid", param);
            throw new Exception("invalid param: " + param);
            //break;
        }
    }
    edoBean.setFields(fieldsList);
    String[] result = args;
    if (args.length >= index + 1) {
        result = Arrays.copyOfRange(args, index + 1, args.length);
    }
    return result;
}

From source file:org.entando.edo.parser.FieldsParser.java

public boolean isValidField(String var) {
    String[] p = var.split(":");
    String fieldName = p[0];/*from   www  . j  a  va 2s . c  om*/
    String fieldArgs = p[1];
    if (null == fieldName || fieldName.isEmpty()) {
        _logger.warn("fieldName is null in {}", var);
        return false;
    }
    if (null == fieldArgs || fieldArgs.isEmpty()) {
        _logger.warn("fieldType is null in {}", var);
        return false;
    }
    String fieldDataType = StringUtils.substringBefore(fieldArgs, "-").toLowerCase();
    return DataTypeManager.getInstance().getDataTypes().containsKey(fieldDataType);
}