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

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

Introduction

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

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:hydrograph.ui.expression.editor.datastructure.ClassDetails.java

private String getJavaDoc(SourceType javaClassFile) throws JavaModelException {
    StringBuffer source = new StringBuffer(javaClassFile.getSource());
    try {/*  w  w w  . j  ava  2  s .c o m*/
        String javaDoc = StringUtils.substring(source.toString(), 0,
                javaClassFile.getJavadocRange().getLength());
        javaDoc = StringUtils.replaceEachRepeatedly(javaDoc, new String[] { "/*", "*/", "*" },
                new String[] { Constants.EMPTY_STRING, Constants.EMPTY_STRING, Constants.EMPTY_STRING });
    } catch (Exception exception) {
        LOGGER.warn("Failed to build java-doc for :{}", javaClassFile);
    }
    return javaDoc;
}

From source file:com.hangum.tadpole.rdb.erd.core.actions.ERDRefreshAction.java

@Override
public void run() {
    if (!MessageDialog.openConfirm(getWorkbenchPart().getSite().getShell(), Messages.get().Confirm,
            Messages.get().ERDRefreshAction_4))
        return;/*from  ww  w.  j  a  v a2 s . c  o m*/

    DB dbModel = rdbEditor.getDb();

    //   table ?  .
    Map<String, Rectangle> mapOldTables = new HashMap<String, Rectangle>();
    for (Table table : dbModel.getTables()) {
        mapOldTables.put(table.getName(), table.getConstraints());
    }

    // remove tables
    int intTableCnt = dbModel.getTables().size();
    for (int i = 0; i < intTableCnt; i++) {
        Table table = dbModel.getTables().get(0);
        table.setDb(null);
    }

    List<String> strTableNames = new ArrayList<String>(mapOldTables.keySet());

    // refresh ui
    try {
        final RdbFactory factory = RdbFactory.eINSTANCE;
        final UserDBDAO userDB = rdbEditor.getUserDB();
        //   ? ?.
        Map<String, Table> mapDBTables = new HashMap<String, Table>();

        List<TableDAO> listTAbles = TadpoleModelUtils.INSTANCE.getTable(userDB, strTableNames);

        for (TableDAO table : listTAbles) {
            Table tableModel = factory.createTable();
            tableModel.setDb(dbModel);
            tableModel.setName(table.getName());

            if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT) {
                tableModel.setComment(""); //$NON-NLS-1$
            } else {
                String tableComment = table.getComment();
                tableComment = StringUtils.substring("" + tableComment, 0, 10); //$NON-NLS-1$
                tableModel.setComment(tableComment);
            }

            mapDBTables.put(tableModel.getName(), tableModel);
            tableModel.setConstraints(mapOldTables.get(table.getName()));
            // column add
            List<TableColumnDAO> columnList = TDBDataHandler.getColumns(userDB, table);
            for (TableColumnDAO columnDAO : columnList) {

                Column column = factory.createColumn();
                column.setDefault(columnDAO.getDefault());
                column.setExtra(columnDAO.getExtra());
                column.setField(columnDAO.getField());
                column.setNull(columnDAO.getNull());
                column.setKey(columnDAO.getKey());
                column.setType(columnDAO.getType());

                String strComment = columnDAO.getComment();
                if (strComment == null)
                    strComment = ""; //$NON-NLS-1$
                strComment = StringUtils.substring("" + strComment, 0, 10); //$NON-NLS-1$
                column.setComment(strComment);

                column.setTable(tableModel);
                tableModel.getColumns().add(column);
            }

        } // end table list

        //  .
        RelationUtil.calRelation(userDB, mapDBTables, dbModel);

    } catch (Exception e) {
        logger.error("Get all table list", e); //$NON-NLS-1$
    }
}

From source file:com.inktomi.wxmetar.MetarParser.java

static boolean parseWinds(String token, final Metar metar) {
    boolean rval = Boolean.FALSE;

    // Winds will be the only element that ends in knots
    if (StringUtils.endsWith(token, "KT")) {

        // At this point, we know we should handle this token
        rval = Boolean.TRUE;/*from   w w w  . j  a v  a2s .c o  m*/

        // Remove the KT
        token = StringUtils.remove(token, "KT");

        // Is it variable?
        if (StringUtils.startsWith(token, "VRB")) {
            metar.winds.variable = Boolean.TRUE;

            // Trim of the VRB
            token = StringUtils.remove(token, "VRB");

            metar.winds.windSpeed = Float.parseFloat(token);

            // Stop processing this token
            return rval;
        }

        // At this point, we know the first 3 chars are wind direction
        metar.winds.windDirection = Integer.parseInt(StringUtils.substring(token, 0, 3));

        // Is it gusting? 17012G24
        int postionOfG = StringUtils.indexOf(token, "G");
        if (postionOfG > -1) {
            metar.winds.windGusts = Float
                    .parseFloat(StringUtils.substring(token, postionOfG + 1, token.length()));
            metar.winds.windSpeed = Float.parseFloat(StringUtils.substring(token, 3, postionOfG));
        }

        // Is it just a normal wind measurement?
        // 26006
        if (postionOfG == -1 && !metar.winds.variable) {
            metar.winds.windSpeed = Float.parseFloat(StringUtils.substring(token, 2, token.length()));
        }
    }

    return rval;
}

From source file:de.interactive_instruments.ShapeChange.Target.SQL.OracleStrategy.java

/**
 * Constraints in Oracle are in their own namespace and do also have the maximum length of 30.
 *///from  w  ww  .j  a va2  s.  c  om
@Override
public String createNameCheckConstraint(String tableName, String propertyName) {
    String truncatedName = StringUtils.substring(tableName.toUpperCase(Locale.ENGLISH), 0, 13) + "_"
            + StringUtils.substring(propertyName.toUpperCase(Locale.ENGLISH), 0, 13);
    String checkConstraintName = truncatedName + "_CK";
    return checkConstraintName;
}

From source file:com.commerce4j.storefront.controllers.CartController.java

@SuppressWarnings("unchecked")
public void update(HttpServletRequest request, HttpServletResponse response) {

    Gson gson = new GsonBuilder().create();
    List<Message> errors = new ArrayList<Message>();
    Map<String, Object> responseModel = new HashMap<String, Object>();

    List<CartDTO> cartEntries = getCart(request);
    Iterator inputSet = request.getParameterMap().keySet().iterator();
    while (inputSet.hasNext()) {
        String paramName = (String) inputSet.next();
        if (StringUtils.contains(paramName, "qty")) {
            String paramValue = request.getParameter(paramName);
            String paramId = StringUtils.substring(paramName, 4, paramName.length());
            if (paramId != null && StringUtils.isNumeric(paramId)) {
                for (CartDTO cartEntry : cartEntries) {
                    int entryId = cartEntry.getItem().getItemId().intValue();
                    int itemId = new Integer(paramId).intValue();
                    int cartQuantity = new Integer(paramValue).intValue();
                    if (entryId == itemId) {
                        cartEntry.setCartQuantity(cartQuantity);
                        cartEntry.setCartSubTotal(cartEntry.getItem().getItemPrice() * cartQuantity);
                        break;
                    }//ww  w .j a  v a 2s  .  co  m
                }
            }
        }
    }

    // fill response model
    if (errors.isEmpty()) {
        responseModel.put("responseCode", SUCCESS);
        responseModel.put("responseMessage", "Cart succesfully updated");
    } else {
        responseModel.put("responseCode", FAILURE);
        responseModel.put("responseMessage", "Error, Cart was not updated");
        responseModel.put("errors", errors);
    }

    // serialize output
    try {
        response.setContentType("application/json");
        OutputStreamWriter os = new OutputStreamWriter(response.getOutputStream());
        String data = gson.toJson(responseModel);
        os.write(data);
        os.flush();
        os.close();
    } catch (IOException e) {
        logger.fatal(e);
    }

}

From source file:com.greenline.guahao.web.module.home.controllers.json.area.JsonAreaController.java

@MethodRemark(value = "remark=??json?,method=ajax")
@RequestMapping(value = "/json/white/area/position", method = RequestMethod.GET)
public @ResponseBody OperationJsonObject areaPosition() {
    OperationJsonObject json = new OperationJsonObject();
    Map<String, String> dataMap = new HashMap<String, String>();

    String position = StringUtils.EMPTY;
    try {/*from w w  w . j av  a 2 s .co  m*/
        // ip???
        position = areaManager.getAreaInfo(IpUtil.getIpAddr(request));
    } catch (Exception e) {
        logger.error("ip?", e);
    }

    String provinceName = StringUtils.EMPTY;
    String cityName = StringUtils.EMPTY;
    if (StringUtils.isNotBlank(position)) {
        if (StringUtils.contains(position, LOCATION_PROVINCE_SUFFIX)) {
            String[] positionArr = StringUtils.split(position, LOCATION_PROVINCE_SUFFIX);
            provinceName = positionArr[0];
            if (positionArr.length > 1) {
                cityName = positionArr[1];
                if (StringUtils.contains(cityName, LOCATION_CITY_SUFFIX)) {
                    cityName = StringUtils.substring(cityName, 0, cityName.length() - 1);
                }
            }
        } else {
            if (StringUtils.contains(position, LOCATION_CITY_SUFFIX)) {
                String[] positionArr = StringUtils.split(position, LOCATION_CITY_SUFFIX);
                provinceName = positionArr[0];
                if (positionArr.length > 1) {
                    cityName = positionArr[1];
                }
            }
        }
    }

    if (StringUtils.isNotBlank(provinceName)) {
        dataMap.put("provice", provinceName);
    }

    if (StringUtils.isNotBlank(cityName)) {
        dataMap.put("city", cityName);
    }

    json.setData(dataMap);
    return json;
}

From source file:gov.nih.nci.cabig.caaers.utils.pdf.MedwatchUtils.java

public static String before(String sentence, int n) {

    int l = sentence.length();

    if (n >= l)
        return sentence;

    char c = sentence.charAt(n);
    if (c == ' ' || c == '\n')
        return sentence.substring(0, n);

    String s1 = StringUtils.substring(sentence, 0, n);
    l = n;/*from   w  w  w .  j a va  2  s .  c o m*/
    c = s1.charAt(l - 1);

    int lastIndex = n;
    if (c != '\n' || c != ' ') {
        int a = s1.lastIndexOf('\n');
        int b = s1.lastIndexOf(' ');
        lastIndex = (a > b) ? a : b;
    }

    return s1.substring(0, lastIndex);

}

From source file:com.hangum.tadpole.manager.core.editor.resource.ResourceManagerLabelProvider.java

@Override
public String getText(Object element) {
    if (element instanceof ManagerListDTO) {
        ManagerListDTO dto = (ManagerListDTO) element;
        return dto.getName();

    } else if (element instanceof UserDBDAO) {
        UserDBDAO dao = (UserDBDAO) element;

        String retText = "";
        if (PublicTadpoleDefine.DBOperationType.PRODUCTION.toString().equals(dao.getOperation_type())) {
            retText = PRODUCTION_SERVER_START_TAG + "[" + StringUtils.substring(dao.getOperation_type(), 0, 1)
                    + "] " + END_TAG;
        } else {//from   www  . j  a va2 s  .c o m
            retText = DEVELOPMENT_SERVER_START_TAG + "[" + StringUtils.substring(dao.getOperation_type(), 0, 1)
                    + "] " + END_TAG;
        }

        // ??  ??? 
        if (dao.getUser_seq() == SessionManager.getUserSeq()) {
            retText += dao.getDisplay_name() + " (" + dao.getUsers() + "@" + dao.getDb() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        } else {
            retText += dao.getDisplay_name(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }

        return retText;
    } else if (element instanceof UserDBResourceDAO) {
        UserDBResourceDAO dao = (UserDBResourceDAO) element;
        String strComment = "".equals(dao.getDescription()) ? "" : " (" + dao.getDescription() + ")";

        return "[" + dao.getShared_type() + "] " + dao.getName() + strComment;
    }

    return "## not set ##"; //$NON-NLS-1$
}

From source file:com.opengamma.util.test.AbstractDbUpgradeTest.java

@Test(groups = TestGroup.UNIT_DB)
public void testDatabaseUpgrade() {
    for (Triple<String, String, String> comparison : _comparisons) {
        /*//from w ww.  j a  va2s.  c  o m
         * System.out.println(comparison.getFirst() + " expected:");
         * System.out.println(comparison.getSecond());
         * System.out.println(comparison.getFirst() + " found:");
         * System.out.println(comparison.getThird());
         */
        int diff = StringUtils.indexOfDifference(comparison.getSecond(), comparison.getThird());
        if (diff >= 0) {
            System.err.println("Difference at " + diff);
            System.err.println("Upgraded --->..."
                    + StringUtils.substring(comparison.getSecond(), diff - 200, diff) + "<-!!!->"
                    + StringUtils.substring(comparison.getSecond(), diff, diff + 200) + "...");
            System.err.println(" Created --->..."
                    + StringUtils.substring(comparison.getThird(), diff - 200, diff) + "<-!!!->"
                    + StringUtils.substring(comparison.getThird(), diff, diff + 200) + "...");
        }
        assertEquals(_databaseType + ": " + comparison.getFirst(), comparison.getSecond(),
                comparison.getThird());
    }
}

From source file:de.iai.ilcd.model.unitgroup.UnitGroup.java

/**
 * Apply cache fields for unit group, those are:
 * <ul>//  w ww .j a v a  2  s.  co m
 * <li>{@link #getDefaultUnit()}</li>
 * </ul>
 */
@Override
@PrePersist
protected void applyDataSetCache() {
    super.applyDataSetCache();
    if (this.referenceUnit != null) {
        this.referenceUnitCache = StringUtils.substring(this.referenceUnit.getName(), 0, 10);
    } else {
        this.referenceUnitCache = null;
    }
}