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:com.adobe.acs.tools.csv_asset_importer.impl.Column.java

public Column(final String raw, final int index) {
    this.index = index;
    this.raw = StringUtils.trim(raw);

    String paramsStr = StringUtils.substringBetween(raw, "{{", "}}");
    String[] params = StringUtils.split(paramsStr, ":");

    if (StringUtils.isBlank(paramsStr)) {
        this.relPropertyPath = this.getRaw();
    } else {//from  ww w  .  ja  v  a 2s  .  co  m
        this.relPropertyPath = StringUtils.trim(StringUtils.substringBefore(this.getRaw(), "{{"));

        if (params.length == 2) {
            this.dataType = nameToClass(StringUtils.stripToEmpty(params[0]));
            this.multi = StringUtils.equalsIgnoreCase(StringUtils.stripToEmpty(params[1]), MULTI);
        }

        if (params.length == 1) {
            if (StringUtils.equalsIgnoreCase(MULTI, StringUtils.stripToEmpty(params[0]))) {
                this.multi = true;
            } else {
                this.dataType = nameToClass(StringUtils.stripToEmpty(params[0]));
            }
        }
    }

    if (StringUtils.contains(this.relPropertyPath, "/")) {
        this.propertyName = StringUtils.trim(StringUtils.substringAfterLast(this.relPropertyPath, "/"));
    } else {
        this.propertyName = StringUtils.trim(this.relPropertyPath);
    }

}

From source file:info.magnolia.objectfactory.ComponentConfigurationPath.java

public ComponentConfigurationPath(String value) {
    if (value.indexOf(':') >= 0) {
        this.repository = StringUtils.substringBefore(value, ":");
        this.path = StringUtils.substringAfter(value, ":");
    } else {/*from  ww  w  .  j  ava  2s .co  m*/
        this.repository = RepositoryConstants.CONFIG;
        this.path = value;
    }
}

From source file:info.magnolia.test.mock.jcr.MockQueryResult.java

public MockQueryResult(Session session, String statement, String language) {
    this.session = session;
    type = StringUtils.substringBefore(StringUtils.substringAfter(statement.toLowerCase(), " from "), " where ")
            .trim();/*from w ww . j av  a 2s .  co m*/

    if (Query.JCR_SQL2.equals(language)) {
        // strip off square brackets required to encapsulate type for sql2 queries
        type = type.substring(1, type.length() - 1);

        String where = StringUtils.substringAfter(statement, "where").trim();
        if (where.indexOf("name()") != -1) {
            // try to get name we are searching for
            name = StringUtils.substringBefore(
                    StringUtils.substringAfter(StringUtils.substringAfter(where, "name()"), "'"), "'");
        }
    }
}

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

public Column(final String raw, final int index) {
    this.index = index;
    this.raw = StringUtils.trim(raw);

    String paramsStr = StringUtils.substringBetween(raw, "{{", "}}");
    String[] params = StringUtils.split(paramsStr, ":");

    if (StringUtils.isBlank(paramsStr)) {
        this.propertyName = this.getRaw();
    } else {/* w w  w  . ja  v a2  s. c o  m*/
        this.propertyName = StringUtils.trim(StringUtils.substringBefore(this.getRaw(), "{{"));

        if (params.length == 2) {
            this.dataType = nameToClass(StringUtils.stripToEmpty(params[0]));
            this.multi = StringUtils.equalsIgnoreCase(StringUtils.stripToEmpty(params[1]), MULTI);
        }

        if (params.length == 1) {
            if (StringUtils.equalsIgnoreCase(MULTI, StringUtils.stripToEmpty(params[0]))) {
                this.multi = true;
            } else {
                this.dataType = nameToClass(StringUtils.stripToEmpty(params[0]));
            }
        }
    }
}

From source file:eionet.cr.filestore.ScriptTemplateDaoImpl.java

/**
 * {@inheritDoc}/* w  w  w.  j av a 2  s. c om*/
 */
@Override
public List<ScriptTemplateDTO> getScriptTemplates() {

    Map<String, ScriptTemplateDTO> scripts = new HashMap<String, ScriptTemplateDTO>();
    for (Object key : PROPERTIES.keySet()) {
        String id = StringUtils.substringBefore((String) key, ".");
        String property = StringUtils.substringAfterLast((String) key, ".");

        ScriptTemplateDTO script = scripts.get(id);
        if (script == null) {
            script = new ScriptTemplateDTO();
            script.setId(id);
            scripts.put(id, script);
        }

        if (property.equals("name")) {
            script.setName(PROPERTIES.getProperty((String) key).trim());
        }

        if (property.equals("script")) {
            script.setScript(PROPERTIES.getProperty((String) key).trim());
        }

    }

    return new ArrayList<ScriptTemplateDTO>(scripts.values());
}

From source file:msi.gama.util.file.GamaFileMetaData.java

public GamaFileMetaData(final String propertyString) {
    final String s = StringUtils.substringBefore(propertyString, DELIMITER);
    if (FAILED.equals(s)) {
        hasFailed = true;/*from w  ww.j a va2  s.  c o m*/
    } else if (s == null || s.isEmpty()) {
        fileModificationStamp = 0;
    } else {
        fileModificationStamp = Long.valueOf(s);
    }
}

From source file:com.amalto.core.history.accessor.record.DataRecordAccessor.java

@SuppressWarnings("rawtypes")
private static LinkedList<PathElement> getPath(DataRecord dataRecord, String path) {
    LinkedList<PathElement> elements = new LinkedList<PathElement>();
    StringTokenizer tokenizer = new StringTokenizer(path, "/"); //$NON-NLS-1$
    DataRecord current = dataRecord;//from   ww w.j  a v  a 2s  .c  o m
    while (tokenizer.hasMoreElements()) {
        String element = tokenizer.nextToken();
        PathElement pathElement = new PathElement();
        if (element.indexOf('@') == 0) {
            pathElement.field = elements.getLast().field;
            pathElement.setter = TypeValue.SET;
            pathElement.getter = TypeValue.GET;
        } else {
            if (current == null) {
                throw new IllegalStateException("Cannot update '" + path + "'."); //$NON-NLS-1$ //$NON-NLS-2$
            }
            if (element.indexOf('[') > 0) {
                pathElement.field = current.getType().getField(StringUtils.substringBefore(element, "[")); //$NON-NLS-1$
                if (!pathElement.field.isMany()) {
                    throw new IllegalStateException(
                            "Expected a repeatable field for '" + element + "' in path '" + path //$NON-NLS-1$ //$NON-NLS-2$
                                    + "'."); //$NON-NLS-1$
                }
                int indexStart = element.indexOf('[');
                int indexEnd = element.indexOf(']');
                if (indexStart < 0 || indexEnd < 0) {
                    throw new RuntimeException(
                            "Field name '" + element + "' did not match many field pattern in path '" //$NON-NLS-1$ //$NON-NLS-2$
                                    + path + "'."); //$NON-NLS-1$
                }
                pathElement.index = Integer.parseInt(element.substring(indexStart + 1, indexEnd)) - 1;
                pathElement.setter = ManyValue.SET;
                pathElement.getter = ManyValue.GET;
                List list = (List) current.get(pathElement.field);
                if (list == null || pathElement.index > list.size() - 1) {
                    throw new IllegalStateException("Cannot update '" + path + "'."); //$NON-NLS-1$ //$NON-NLS-2$
                }
                Object value = list.get(pathElement.index);
                if (value instanceof DataRecord) {
                    current = (DataRecord) value;
                } else if (value instanceof List) {
                    throw new IllegalStateException();
                }
            } else {
                pathElement.field = current.getType().getField(element);
                pathElement.setter = SimpleValue.SET;
                pathElement.getter = SimpleValue.GET;
                if (pathElement.field instanceof ContainedTypeFieldMetadata
                        || pathElement.field instanceof ReferenceFieldMetadata) {
                    Object value = current.get(pathElement.field);
                    if (value instanceof DataRecord) {
                        current = (DataRecord) value;
                    }
                }
            }
        }
        elements.add(pathElement);
    }
    return elements;
}

From source file:com.cndatacom.core.orm.PropertyFilter.java

/**
 * @param filterName ,???. /* w  w  w .  j a  v a  2  s. c  o m*/
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    this.filterName = filterName;
    this.value = value;

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    //,EQ
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    //?,S?I
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    //propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);
    propertyNames = propertyNameStr.split(PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    if (propertyNameStr.indexOf(LEFT_JION) != -1) {
        isLeftJion = true;
    }
    //
    Object value_ = null;
    if (null == value || value.equals("")) {

        this.propertyValue = null;

    } else {
        this.propertyValue = ReflectionUtils.convertStringToObject(value, propertyType);
        value_ = propertyValue;
        //?1
        if (propertyType.equals(Date.class) && filterName.indexOf("LTD") > -1) {
            propertyValue = DateUtils.addDays((Date) propertyValue, 1);
        }
    }
    //request?
    String key = propertyNames[0].replace(".", "_").replace(":", "_");
    //      if(propertyType!=Date.class)
    ////      Struts2Utils.getRequest().setAttribute(key, propertyValue);
    ////      else{
    ////         if(Struts2Utils.getRequest().getAttribute(key)!=null){
    ////            String time_begin=Struts2Utils.getRequest().getAttribute(key)+"";
    ////            Struts2Utils.getRequest().setAttribute(key, time_begin+"="+com.cndatacom.common.utils.DateUtil.format((Date)value_,"yyyy-MM-dd"));         
    ////         }else{
    ////      Struts2Utils.getRequest().setAttribute(key, com.cndatacom.common.utils.DateUtil.format((Date)value_,"yyyy-MM-dd"));   
    ////         }
    //      
    //      }

}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResult.java

/**
 *
 * @param variableName/*from   w ww  . ja v a 2 s.  com*/
 * @param methodName
 * @param returnType
 */
public MemberLookupResult(String variableName, String methodName, String returnType) {
    this.variableName = variableName;
    this.methodName = methodName;

    //TODO: this is a hack to get support for list, set, map, enumeration, array and collection
    String tmp = returnType;
    if (StringUtils.startsWith(returnType, List.class.getName())
            || StringUtils.startsWith(returnType, Set.class.getName())
            || StringUtils.startsWith(returnType, Map.class.getName())
            || StringUtils.startsWith(returnType, Iterator.class.getName())
            || StringUtils.startsWith(returnType, Enum.class.getName())
            || StringUtils.startsWith(returnType, Collection.class.getName())) {
        while (StringUtils.contains(tmp, "<") && StringUtils.contains(tmp, ">")) {
            tmp = StringUtils.substringBetween(tmp, "<", ">");
        }
        if (StringUtils.contains(tmp, ",")) {
            // we want the first variable
            tmp = StringUtils.substringBefore(tmp, ",");
        }
    } else if (StringUtils.endsWith(returnType, "[]")) {
        tmp = StringUtils.substringBeforeLast(returnType, "[]");
    }

    this.returnType = tmp;
}

From source file:com.iadams.sonarqube.puppet.checks.InheritsAcrossNamespaceCheck.java

@Override
public void visitNode(AstNode node) {
    String inheritedModuleName = StringUtils
            .substringBefore(node.getFirstChild(PuppetGrammar.CLASSNAME_OR_DEFAULT).getTokenValue(), "::");
    String classModuleName = StringUtils
            .substringBefore(node.getParent().getFirstChild(PuppetGrammar.CLASSNAME).getTokenValue(), "::");

    if (!inheritedModuleName.equals(classModuleName)) {
        addIssue(node, this, "Remove this inheritance from an external module class.");
    }//from  w  ww .j  av  a2s  .co m
}