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.pieframework.model.repository.ModelStore.java

public static List<ExpressionEntry> parseInstanceFile(File file) throws IOException {
    List<ExpressionEntry> retList = new ArrayList<ExpressionEntry>();
    LineIterator it = FileUtils.lineIterator(file);
    try {//  w  ww . ja va2  s  . c om
        while (it.hasNext()) {
            String line = it.nextLine();
            if (StringUtils.startsWith(line, "#")) {
                // ignore comments
            } else {
                String expression = StringUtils.trimToEmpty(StringUtils.substringBefore(line, "="));
                String value = StringUtils.trimToEmpty(StringUtils.substringAfter(line, "="));
                if (StringUtils.isNotEmpty(expression) && StringUtils.isNotEmpty(value)) {
                    retList.add(new ExpressionEntry().withExpression(expression).withValue(value));
                }
            }
        }
    } finally {
        it.close();
    }
    return retList;
}

From source file:com.hangum.tadpole.rdb.core.dialog.dbconnect.composite.MySQLLoginComposite.java

@Override
public void crateComposite() {
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.verticalSpacing = 2;//from ww w  .  jav  a2  s.c o  m
    gridLayout.horizontalSpacing = 2;
    gridLayout.marginHeight = 2;
    gridLayout.marginWidth = 2;
    setLayout(gridLayout);
    setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite compositeBody = new Composite(this, SWT.NONE);
    GridLayout gl_compositeBody = new GridLayout(1, false);
    gl_compositeBody.verticalSpacing = 2;
    gl_compositeBody.horizontalSpacing = 2;
    gl_compositeBody.marginHeight = 2;
    gl_compositeBody.marginWidth = 2;
    compositeBody.setLayout(gl_compositeBody);
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    preDBInfo = new PreConnectionInfoGroup(compositeBody, SWT.NONE, listGroupName);
    preDBInfo.setText(Messages.get().MSSQLLoginComposite_preDBInfo_text);
    preDBInfo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    grpConnectionType = new Group(compositeBody, SWT.NONE);
    grpConnectionType.setLayout(new GridLayout(5, false));
    grpConnectionType.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    grpConnectionType.setText(Messages.get().DatabaseInformation);

    Label lblHost = new Label(grpConnectionType, SWT.NONE);
    lblHost.setText(Messages.get().Host);

    textHost = new Text(grpConnectionType, SWT.BORDER);
    textHost.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabelPort = new Label(grpConnectionType, SWT.NONE);
    lblNewLabelPort.setText(Messages.get().Port);

    textPort = new Text(grpConnectionType, SWT.BORDER);
    textPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    Button btnPing = new Button(grpConnectionType, SWT.NONE);
    btnPing.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            pingTest(textHost.getText(), textPort.getText());
        }
    });
    btnPing.setText(Messages.get().PingTest);

    Label lblNewLabelDatabase = new Label(grpConnectionType, SWT.NONE);
    lblNewLabelDatabase.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));
    lblNewLabelDatabase.setText(Messages.get().Database);

    textDatabase = new Text(grpConnectionType, SWT.BORDER);
    textDatabase.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));

    Label lblUser = new Label(grpConnectionType, SWT.NONE);
    lblUser.setText(Messages.get().User);

    textUser = new Text(grpConnectionType, SWT.BORDER);
    textUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblPassword = new Label(grpConnectionType, SWT.NONE);
    lblPassword.setText(Messages.get().Password);

    textPassword = new Text(grpConnectionType, SWT.BORDER | SWT.PASSWORD);
    textPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    new Label(grpConnectionType, SWT.NONE);

    Label label = new Label(grpConnectionType, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));

    Label lblJdbcOptions = new Label(grpConnectionType, SWT.NONE);
    lblJdbcOptions.setText(Messages.get().JDBCOptions);

    textJDBCOptions = new Text(grpConnectionType, SWT.BORDER);
    textJDBCOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));

    Label lblLocale = new Label(grpConnectionType, SWT.NONE);
    lblLocale.setText(Messages.get().CharacterSet);

    comboLocale = new Combo(grpConnectionType, SWT.NONE);
    comboLocale.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
    comboLocale.setVisibleItemCount(12);

    for (String val : DBLocaleUtils.getMySQLList()) {
        comboLocale.add(val);
        comboLocale.setData(StringUtils.substringBefore(val, "|").trim(), val);
    }
    comboLocale.select(0);

    othersConnectionInfo = new OthersConnectionRDBGroup(this, SWT.NONE, getSelectDB());
    othersConnectionInfo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    init();
}

From source file:jef.tools.security.EncrypterUtil.java

/**
 * ??(RAW KEY)// w  w  w.java 2s .com
 * 
 * @param value
 * @param algom
 * @return
 */
public static final SecretKey toSecretKey(byte[] value, String algorithm) {
    if (algorithm.indexOf("/") > -1) {
        // ??key
        // ChiperDES/ECB/NOPADDINGkeyDES?
        return new RawSecretKeySpec(value, algorithm, StringUtils.substringBefore(algorithm, "/"));
    } else {
        return new SecretKeySpec(value, algorithm);
    }
}

From source file:info.magnolia.module.workflow.jcr.JCRWorkItemAPI.java

/**
 * create the jcr node path for work Item by its id
 * @param eid//from  ww  w  .  j av  a2s.c  o m
 */
public String createPathFromId(FlowExpressionId eid) {
    String wlInstId = eid.getWorkflowInstanceId();
    // FIXME someone who knows the code better should have a look
    String groupString = StringUtils.right(StringUtils.substringBefore(wlInstId, "."), 3);
    int groupNumber = Integer.parseInt(groupString) % 100;
    StringBuffer buffer = new StringBuffer(eid.getWorkflowDefinitionName());
    buffer.append(WorkflowConstants.SLASH);
    buffer.append(eid.getWorkflowDefinitionRevision());
    buffer.append(WorkflowConstants.SLASH);
    buffer.append(groupNumber);
    buffer.append(WorkflowConstants.SLASH);
    buffer.append(eid.getWorkflowInstanceId());
    buffer.append(WorkflowConstants.SLASH);
    buffer.append(eid.getExpressionName());
    buffer.append(WorkflowConstants.SLASH);
    buffer.append(eid.getExpressionId());

    return convertPath(buffer.toString());
}

From source file:com.sfs.whichdoctor.dao.onlineapplication.BasicTrainingOnlineApplicationHandler.java

/**
 * Gets the JSP key for the next step./*  w w  w . j a v a 2  s .co  m*/
 * An error is thrown if the user does not have the privileges to access this step.
 *
 * @param application the online application
 * @param user the user
 * @param privileges the privileges
 * @return the next step
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final String getNextJSPKey(final OnlineApplicationBean application, final UserBean user,
        final PrivilegesBean privileges) throws WhichDoctorDaoException {

    if (user == null) {
        throw new WhichDoctorDaoException("The user cannot be null");
    }
    if (privileges == null) {
        throw new WhichDoctorDaoException("The privileges cannot be null");
    }

    String key = "";

    String status = application.getStatus();
    if (StringUtils.contains(status, " )")) {
        status = StringUtils.substringBefore(status, " (");
    }
    if (StringUtils.equalsIgnoreCase(status, "Unprocessed")) {
        if (privileges.getPrivilege(user, "people", "create")) {
            key = "PEOPLE_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm membership details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Confirm email address")) {
        if (privileges.getPrivilege(user, "emails", "create")) {
            key = "EMAIL_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm email details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Confirm address")) {
        if (privileges.getPrivilege(user, "addresses", "create")) {
            key = "ADDRESS_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm address details");
        }
    }
    if (StringUtils.containsIgnoreCase(status, " phone") || StringUtils.containsIgnoreCase(status, " fax")) {
        if (privileges.getPrivilege(user, "phones", "create")) {
            key = "PHONE_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm phone details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Confirm secondary qualifications")) {
        if (privileges.getPrivilege(user, "qualifications", "create")) {
            key = "QUALIFICATION_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm qualifications details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Confirm rotation details")) {
        if (privileges.getPrivilege(user, "rotations", "create")) {
            key = "ROTATIONS_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm rotation details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Issue invoice")) {
        if (privileges.getPrivilege(user, "invoices", "create")) {
            key = "DEBITS_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to issue invoice");
        }
    }

    return key;
}

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

/**
 * countHql./*w  ww. j  a  v  a 2s  .  c  o m*/
 * 
 * ???hql?,??hql?count?.
 */
private String prepareCountHql(String orgHql) {
    String fromHql = orgHql;
    // select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;
    return countHql;
}

From source file:de.hybris.platform.accountsummaryaddon.document.dao.impl.DefaultPagedB2BDocumentDao.java

protected String getFiedName(final String fieldName) {
    if (StringUtils.endsWith(fieldName, "_max") || StringUtils.endsWith(fieldName, "_min")) {
        return StringUtils.substringBefore(fieldName, "_");
    }/*from ww w .  j  a  va2 s .c o m*/
    return fieldName;
}

From source file:com.hangum.tadpole.engine.sql.util.OracleObjectCompileUtils.java

/**
 * package compile/*from   w ww. j  av  a  2  s  .com*/
 * 
 * @param objectName
 * @param userDB
 */
public static String packageCompile(String strObjectName, UserDBDAO userDB) throws Exception {
    //TODO: RequestQuery?   ? ?.  
    ProcedureFunctionDAO packageDao = new ProcedureFunctionDAO();
    if (StringUtils.contains(strObjectName, '.')) {
        //??   ?? ...
        packageDao.setSchema_name(StringUtils.substringBefore(strObjectName, "."));
        packageDao.setPackagename(StringUtils.substringAfter(strObjectName, "."));
        packageDao.setName(StringUtils.substringAfter(strObjectName, "."));
    } else {
        //    ?    .
        packageDao.setSchema_name(userDB.getSchema());
        packageDao.setPackagename(strObjectName);
        packageDao.setName(strObjectName);
    }

    return packageCompile(packageDao, userDB, userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT);
}

From source file:info.magnolia.jcr.util.PropertiesImportExport.java

protected Object convertPropertyStringToObject(String valueStr) {
    if (contains(valueStr, ':')) {
        final String type = StringUtils.substringBefore(valueStr, ":");
        final String value = StringUtils.substringAfter(valueStr, ":");

        // there is no beanUtils converter for Calendar
        if (type.equalsIgnoreCase("date")) {
            return ISO8601.parse(value);
        } else if (type.equalsIgnoreCase("binary")) {
            return new ByteArrayInputStream(value.getBytes());
        } else {//w  w  w .  j  av  a2s .  co m
            try {
                final Class<?> typeCl;
                if (type.equals("int")) {
                    typeCl = Integer.class;
                } else {
                    typeCl = Class.forName("java.lang." + StringUtils.capitalize(type));
                }
                return ConvertUtils.convert(value, typeCl);
            } catch (ClassNotFoundException e) {
                // possibly a stray :, let's ignore it for now
                return valueStr;
            }
        }
    }
    // no type specified, we assume it's a string, no conversion
    return valueStr;
}

From source file:au.com.redboxresearchdata.fascinator.harvester.MintJsonHarvester.java

private void appendToPathPrefixOfHarvestKeyValue(JsonObject harvest, String key, String appendage)
        throws HarvesterException {
    String currentValue = getHarvestKeyValue(harvest, key);
    // current rules config path may have been updated - ensure only the first prefix of path is used
    updateHarvestFileKeyValue(harvest, key, StringUtils.substringBefore(currentValue, "/"), appendage + "/");
}