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) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:com.haulmont.cuba.gui.xml.layout.loaders.WindowLoader.java

protected void loadTimer(ComponentsFactory factory, final Window component, Element element) {
    Timer timer = factory.createTimer();
    timer.setXmlDescriptor(element);// www .  java  2s  .  c o m
    timer.setId(element.attributeValue("id"));
    String delay = element.attributeValue("delay");
    if (StringUtils.isEmpty(delay)) {
        throw new GuiDevelopmentException("Timer 'delay' can't be empty", context.getCurrentFrameId(),
                "Timer ID", timer.getId());
    }

    int value;
    try {
        value = Integer.parseInt(delay);
    } catch (NumberFormatException e) {
        throw new GuiDevelopmentException("Timer 'delay' must be numeric", context.getFullFrameId(),
                ParamsMap.of("Timer delay", delay, "Timer ID", timer.getId()));
    }

    if (value <= 0) {
        throw new GuiDevelopmentException("Timer 'delay' must be greater than 0", context.getFullFrameId(),
                "Timer ID", timer.getId());
    }

    timer.setDelay(value);
    timer.setRepeating(Boolean.parseBoolean(element.attributeValue("repeating")));

    String onTimer = element.attributeValue("onTimer");
    if (StringUtils.isNotEmpty(onTimer)) {
        String timerMethodName = onTimer;
        if (StringUtils.startsWith(onTimer, "invoke:")) {
            timerMethodName = StringUtils.substring(onTimer, "invoke:".length());
        }
        timerMethodName = StringUtils.trim(timerMethodName);

        addInitTimerMethodTask(timer, timerMethodName);
    }

    String autostart = element.attributeValue("autostart");
    if (StringUtils.isNotEmpty(autostart) && Boolean.parseBoolean(autostart)) {
        addAutoStartTimerTask(timer);
    }

    timer.setFrame(context.getFrame());

    component.addTimer(timer);
}

From source file:com.ning.killbill.zuora.zuora.ZuoraApi.java

private String getLastName(com.ning.billing.account.api.Account account) {
    return StringUtils.defaultIfEmpty(
            StringUtils.substring(account.getName(), account.getFirstNameLength() + 1), account.getEmail());
}

From source file:hydrograph.ui.dataviewer.adapters.DataViewerAdapter.java

private String getType(String databaseName) throws IOException {
    StringBuffer typeString = new StringBuffer();
    String debugFileName = debugDataViewer.getDebugFileName();
    String debugFileLocation = debugDataViewer.getDebugFileLocation();
    if (ViewDataSchemaHelper.INSTANCE.getFieldsFromSchema(
            debugFileLocation + debugFileName + AdapterConstants.SCHEMA_FILE_EXTENTION) == null) {
        return "";
    }/*w w w.ja  va 2 s. co  m*/
    Map<String, String> fieldAndTypes = new HashMap<String, String>();
    for (Field field : ViewDataSchemaHelper.INSTANCE
            .getFieldsFromSchema(debugFileLocation + debugFileName + AdapterConstants.SCHEMA_FILE_EXTENTION)
            .getField()) {
        fieldAndTypes.put(StringUtils.lowerCase(field.getName()), field.getType().value());
    }
    try (BufferedReader bufferedReader = new BufferedReader(
            new FileReader(new File(databaseName + tableName + AdapterConstants.CSV)))) {
        String firstLine = bufferedReader.readLine();
        StringTokenizer stringTokenizer = new StringTokenizer(firstLine, ",");
        int countTokens = stringTokenizer.countTokens();
        for (int i = 0; i < countTokens; i++) {
            String columnName = stringTokenizer.nextToken();
            String typeName = fieldAndTypes.get(StringUtils.lowerCase(columnName));
            typeString.append(StringUtils.substring(typeName, StringUtils.lastIndexOf(typeName, ".") + 1));
            if (i != countTokens - 1) {
                typeString.append(",");
            }
        }
    } catch (IOException ioException) {
        logger.error("Failed to read view data file column headers", ioException);
        throw ioException;
    }
    return typeString.toString();
}

From source file:com.huawei.streaming.cql.DriverContext.java

private ClassLoader addToClassPath(ClassLoader classLoader, String[] newPaths) throws ExecutorException {
    URLClassLoader loader = (URLClassLoader) classLoader;
    List<URL> curPath = Arrays.asList(loader.getURLs());
    List<URL> newPath = Lists.newArrayList();

    for (URL onePath : curPath) {
        newPath.add(onePath);//from  w ww .  ja  v  a  2s  .  co m
    }
    curPath = newPath;
    if (newPaths != null) {
        for (String onestr : newPaths) {
            if (StringUtils.indexOf(onestr, FILE_PREFIX) == 0) {
                onestr = StringUtils.substring(onestr, CQLConst.I_7);
            }

            URL oneurl = getFileURL(onestr);

            if (!curPath.contains(oneurl)) {
                curPath.add(oneurl);
            }
        }
    }

    return new URLClassLoader(curPath.toArray(new URL[0]), loader);
}

From source file:hydrograph.ui.perspective.ApplicationWorkbenchWindowAdvisor.java

private static String getInstallationConfigPath() {
    String path = Platform.getInstallLocation().getURL().getPath();
    if (StringUtils.isNotBlank(path) && StringUtils.startsWith(path, "/") && OSValidator.isWindows()) {
        path = StringUtils.substring(path, 1);
    }/*from w  w  w  . ja v a  2 s .c om*/

    return path + "config/service/config";
}

From source file:com.xx_dev.apn.proxy.ApnProxyUserAgentForwardHandler.java

private String getPartialUrl(String fullUrl) {
    if (StringUtils.startsWith(fullUrl, "http")) {
        int idx = StringUtils.indexOf(fullUrl, "/", 7);
        return idx == -1 ? "/" : StringUtils.substring(fullUrl, idx);
    }/*from www .j av a 2  s  .  c  o m*/

    return fullUrl;
}

From source file:gtu.youtube.JavaYoutubeVideoUrlHandler.java

private String getParamStr_forCatch(String title, String baseUrlString, int start, String catchPattern) {
    String tmpUrl = StringUtils.substring(baseUrlString, start);
    Pattern ptn = Pattern.compile(catchPattern);
    Matcher mth = ptn.matcher(tmpUrl);
    if (mth.find()) {
        return mth.group();
    }/*from  ww w  .  j  ava2  s .c o m*/
    throw new RuntimeException("?" + title + " : " + tmpUrl);
}

From source file:com.mightypocket.ashot.Mediator.java

private JToolBar createToolBar() {
    ApplicationActionMap actionMap = getActionMap();
    JToolBar bar = new JToolBar();
    bar.setRollover(true);/*from ww  w .  j av a2 s.c om*/
    toolBarMap.clear();
    final boolean hideText = !p.getBoolean(PREF_GUI_SHOW_TEXT_IN_TOOLBAR, true);
    for (String actionName : TOOLBAR) {
        if (TOOLBAR_SEPARATOR.equals(actionName)) {
            bar.addSeparator();
        } else {
            AbstractButton bt;
            if (actionName.startsWith(TOOLBAR_TOGGLE_BUTTON)) {
                actionName = StringUtils.substring(actionName, TOOLBAR_TOGGLE_BUTTON.length());
                bt = new JToggleButton(actionMap.get(actionName));
            } else {
                bt = new JButton(actionMap.get(actionName));
            }
            bt.setFocusable(false);
            bt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
            bt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
            bt.setHideActionText(hideText);
            bar.add(bt);
            toolBarMap.put(actionName, bt);
        }
    }

    return bar;
}

From source file:gtu.youtube.JavaYoutubeVideoUrlHandler.java

private String getParamStr(String baseUrlString, int start, String endPattern) {
    String tmpUrl = StringUtils.substring(baseUrlString, start);
    Pattern ptn = Pattern.compile(endPattern);
    Matcher mth = ptn.matcher(tmpUrl);
    int pos = -1;
    if (mth.find()) {
        pos = mth.start();/*from www.j  a  va  2s .com*/
    } else {
        pos = baseUrlString.length();
    }
    String paramStr = StringUtils.substring(tmpUrl, 0, pos);
    return paramStr;
}

From source file:com.prowidesoftware.swift.model.field.SwiftParseUtils.java

/**
 * Returns the numeric suffix of the value.
 * The split is made when the first numeric character is found.
 * For example:<br />//from ww w.j a v a  2 s .co  m
 * ABCD2345,33 will be return 2345,33<br />
 * If the value does not contain any numeric character <code>null</code> is returned.
 *
 * @param value
 * @return s
 */
public static String getNumericSuffix(final String value) {
    if (value != null && value.length() > 0) {
        int i = 0;
        while (i < value.length() && !StringUtils.isNumeric("" + value.charAt(i))) {
            i++;
        }
        if (i < value.length()) {
            return StringUtils.substring(value, i);
        }
    }
    return null;
}