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:org.xaloon.wicket.component.repository.util.RepositoryHelper.java

public static String getFileName(String nodePath) {
    final String nstr = StringUtils.left(nodePath, nodePath.lastIndexOf("/"));
    return StringUtils.substring(nstr, nstr.lastIndexOf("/") + 1);
}

From source file:org.xwiki.platform.patchservice.impl.ObjectPropertyDeleteAtOperation.java

/**
 * {@inheritDoc}/*from  w ww .ja v  a 2s .  c o m*/
 */
public void apply(XWikiDocument doc, XWikiContext context) throws XWikiException {
    BaseObject obj = doc.getObject(this.className, this.number);
    if (obj == null) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN,
                new Formatter().format("Invalid object type/number: %s[%d]",
                        new Object[] { this.className, new Integer(this.number) }).toString());
    }
    try {
        String value = obj.getLargeStringValue(this.propertyName);
        if (!this.position.checkPosition(value)
                || !this.position.getTextAfterPosition(value).startsWith(this.deletedContent)) {
            throw new Exception();
        }
        value = this.position.getTextBeforePosition(value) + StringUtils
                .substring(this.position.getTextAfterPosition(value), this.deletedContent.length());
        obj.set(this.propertyName, value, context);
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN,
                new Formatter().format("Invalid deleted text: [%s] for object property [%s]",
                        new Object[] { this.deletedContent, this.propertyName }).toString());
    }
}

From source file:org.xwiki.platform.patchservice.impl.PositionImpl.java

/**
 * {@inheritDoc}/*  w  w  w. j  a v a 2  s  .  co  m*/
 */
public String getTextAfterPosition(String text) {
    String[] rows = StringUtils.splitPreserveAllTokens(text, SEPARATOR);
    if (ArrayUtils.getLength(rows) <= this.row) {
        return "";
    }
    String textAfter = StringUtils.substring(rows[this.row], this.column)
            + ((this.row + 1 < rows.length) ? SEPARATOR : "")
            + StringUtils.join(ArrayUtils.subarray(rows, this.row + 1, rows.length), SEPARATOR);
    return (this.span <= 0) ? textAfter : StringUtils.substring(textAfter, this.span);
}

From source file:org.yes.cart.payment.impl.AuthorizeNetSimPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from  w  ww.  j a va  2s . co m
 * All fields are hidden, hence not need to localize and etc.
 */
@Override
public String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount,
        final String currencyCode, final String orderGuid, final Payment payment) {

    final String apiLoginId = getParameterValue(AN_API_LOGIN_ID);
    final String amountString = "" + amount;

    final Random rnd = new Random(new Date().getTime());
    final Fingerprint fingerprint = Fingerprint.createFingerprint(apiLoginId,
            getParameterValue(AN_TRANSACTION_KEY), rnd.nextInt(99999999), amountString);
    final long x_fp_sequence = fingerprint.getSequence();
    final long x_fp_timestamp = fingerprint.getTimeStamp();
    final String x_fp_hash = fingerprint.getFingerprintHash();

    final StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(getHiddenField("x_login", apiLoginId));
    stringBuilder.append(getHiddenField("x_fp_sequence", x_fp_sequence));
    stringBuilder.append(getHiddenField("x_fp_timestamp", x_fp_timestamp));
    stringBuilder.append(getHiddenField("x_fp_hash", x_fp_hash));
    stringBuilder.append(getHiddenField("x_version", "3.1"));
    stringBuilder.append(getHiddenField("x_method", "CC"));
    stringBuilder.append(getHiddenField("x_type", "AUTH_CAPTURE"));
    stringBuilder.append(getHiddenField("x_amount", amountString));
    stringBuilder.append(getHiddenField("x_show_form", "payment_form"));
    stringBuilder.append(getHiddenField("x_test_request", getParameterValue(AN_TEST_REQUEST)));

    //not mandatory parameters
    stringBuilder
            .append(getHiddenField("x_invoice_num", StringUtils.substring(orderGuid.replace("-", ""), 20))); // limit to 20 chast lenght
    stringBuilder.append(
            getHiddenField("x_description", StringUtils.defaultString(getParameterValue(AN_DESCRIPTION))));

    stringBuilder.append(getHiddenField("x_relay_response", "TRUE"));

    stringBuilder.append(getHiddenField(ORDER_GUID, orderGuid)); // this will be bypassed via payment gateway to restore it latter

    return stringBuilder.toString();
}

From source file:pt.webdetails.cdc.ws.MondrianCacheCleanService.java

private Connection getMdxConnection(String catalog) {

    if (catalog != null && catalog.startsWith("/")) {
        catalog = StringUtils.substring(catalog, 1);
    }//ww  w . j a va 2  s .co  m

    MondrianCatalog selectedCatalog = mondrianCatalogService.getCatalog(catalog,
            PentahoSessionHolder.getSession());

    if (selectedCatalog == null) {
        logger.error("Received catalog '" + catalog + "' doesn't appear to be valid");
        return null;
    }

    String connectStr = selectedCatalog.getDataSourceInfo() + "; Catalog=" + selectedCatalog.getDefinition();
    logger.info("Found catalog " + selectedCatalog.toString());

    Connection conn = null;
    try {
        conn = getConnectionFromString(connectStr);
        if (conn == null) {
            logger.warn("Couldn't get connection for " + connectStr);
        }
    } catch (Exception e) {
        logger.error("Error while creating connection", e);
    }
    return conn;
}

From source file:pt.webdetails.cdf.dd.olap.OlapUtils.java

private Connection getMdxConnection(String catalog) {

    if (catalog != null && catalog.startsWith("/")) {
        catalog = StringUtils.substring(catalog, 1);
    }/*w w  w .j av a 2  s . c o m*/

    MondrianCatalog selectedCatalog = mondrianCatalogService.getCatalog(catalog, userSession);
    if (selectedCatalog == null) {
        logger.error("Received catalog '" + catalog + "' doesn't appear to be valid");
        return null;
    }
    selectedCatalog.getDataSourceInfo();
    logger.info("Found catalog " + selectedCatalog.toString());

    String connectStr = "provider=mondrian;dataSource=" + selectedCatalog.getEffectiveDataSource().getJndi()
            + "; Catalog=" + selectedCatalog.getDefinition();

    return getMdxConnectionFromConnectionString(connectStr);
}

From source file:pt.webdetails.cpf.olap.AbstractOlapUtils.java

protected Connection getMdxConnection(String catalog) {

    if (catalog != null && catalog.startsWith("/")) {
        catalog = StringUtils.substring(catalog, 1);
    }/*from   ww  w  .  ja  v  a2  s. c  o  m*/

    MondrianCatalog selectedCatalog = mondrianCatalogService.getCatalog(catalog, userSession);
    if (selectedCatalog == null) {
        logger.error("Received catalog '" + catalog + "' doesn't appear to be valid");
        return null;
    }
    selectedCatalog.getDataSourceInfo();
    logger.info("Found catalog " + selectedCatalog.toString());

    String connectStr = "provider=mondrian;dataSource=" + getJndiFromCatalog(selectedCatalog) + "; Catalog="
            + selectedCatalog.getDefinition();

    return getMdxConnectionFromConnectionString(connectStr);
}

From source file:randori.compiler.asdoc.internal.template.asdoc.ASDocRowConverter.java

public List<String> addSeeTags(IRowTemplate template, IDocumentableDefinition definition, String tagName) {
    IDocComment comment = (IDocComment) definition.getExplicitSourceComment();
    if (!comment.hasTag(tagName))
        return null;

    List<String> result = new ArrayList<String>();

    List<IDocTag> tags = comment.getTags(tagName);
    for (IDocTag tag : tags) {

        @SuppressWarnings("unused")
        String text = null;//from w w w . ja v a  2  s. com
        String anchor = null;
        String body = tag.getDescription().trim();
        String linx = StringUtils.substringBefore(body, " ");
        if (linx != null && !linx.equals(""))
            anchor = linx;

        int index = body.indexOf(" ");
        if (index != -1)
            text = StringUtils.substring(body, index);

        if (anchor == null)
            continue;

        if (anchor.indexOf("://") != -1 || anchor.indexOf("mailto:") != -1) {
            //anchor = returnLink(anchor, text);
        } else if (body.indexOf('"') == 0) {
            anchor = body.trim();
        } else if (body.indexOf(".html") == body.length() - 5) {
            //anchor = returnLink(anchor, text);
        } else if (body.indexOf("#") == 0) {
            IDocumentableDefinition member = getConfiguration().getAccess().getDefinition(body);
            if (member == null) {
                anchor = body.trim();
            } else {
                anchor = getConverter().returnDefinitionLink(member, getConverter().getPackageContextString());
            }
        } else {
            ITypeDefinition type = getConfiguration().getAccess().getType(body.trim());
            if (type != null) {
                anchor = getConverter().returnTypeLink(type, getConverter().getPackageContextString());
            } else {
                anchor = body.trim();
            }
        }

        result.add(anchor);
    }

    return result;
}

From source file:uk.ac.ebi.bioinvindex.utils.datasourceload.DataLocationManager.java

/**
 * Converts an accession to something suitable for being used as file name. Which means replacing some bad characters,
 * such as ":" and other stuff./*  w w w  . j ava 2s  . c o  m*/
 * <p/>
 * <b>Please note</b>: this <b>is not</b> the inverse of {@link #filePath2Id(String)}.
 *
 * @param accession
 * @return
 */
public static String accession2FileName(String accession) {
    if (accession == null || accession.length() == 0)
        return accession;

    accession = accession.trim();
    if (accession.length() == 0)
        return accession;

    // Deal with the protocol in the URL
    int i = accession.indexOf(':');
    if (i != -1) {
        accession = StringUtils.substring(accession, i + 1);
        if (accession.startsWith("//"))
            accession = StringUtils.substring(accession, 2);
    }

    String replacedChars = ":/.? ()[]{}";
    accession = StringUtils.replaceChars(accession, replacedChars,
            StringUtils.repeat("_", replacedChars.length()));

    return accession;
}

From source file:uk.ac.ebi.bioinvindex.utils.datasourceload.DataLocationManager.java

/**
 * Converts a file path into a string which is more appropriate as identifier. At the moment replaces '/' and other bad
 * characters with '_', removes extension (the last '.' until the end of the string), replaces remaining '.'s with
 * '_'./*from   w  ww  .java 2 s.  c o  m*/
 * <p/>
 * <b>Please note</b>: this <b>is not</b> the inverse of {@link #accession2FileName(String)}.
 */
public static String filePath2Id(String path) {
    if (path == null || path.length() == 0)
        return path;

    path = path.trim();
    if (path.length() == 0)
        return path;

    // Deal with the protocol in the URL
    int i = path.indexOf(':');
    if (i != -1) {
        path = StringUtils.substring(path, i + 1);
        if (path.startsWith("//"))
            path = StringUtils.substring(path, 2);
    }

    path = path.replace('/', '_');

    // Remove the last dot and what it follows, this is considered the extension
    i = path.lastIndexOf('.');
    if (i != -1)
        path = path.substring(0, i);

    // If there are still further dots, convert them into nicer characters
    path = path.replace('.', '_');

    return path;
}