Example usage for org.apache.commons.lang3 StringUtils substringAfter

List of usage examples for org.apache.commons.lang3 StringUtils substringAfter

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfter.

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:org.xwiki.contrib.jira.macro.internal.source.ListJIRADataSource.java

/**
 * @param macroContent the macro content listing JIRA issue ids and optional notes
 * @return the list of issue ids and optional notes specified in the macro content
 */// www  .  j  ava2 s.  co  m
public List<Pair<String, String>> parseIds(String macroContent) {
    List<Pair<String, String>> ids = new ArrayList<Pair<String, String>>();
    if (macroContent != null) {
        for (String issueLine : macroContent.split("\\r?\\n")) {
            // Split on pipe symbol
            String issue = StringUtils.substringBefore(issueLine, PIPE).trim();
            String note = StringUtils.substringAfter(issueLine, PIPE).trim();
            // Only add if the issue is not empty
            if (StringUtils.isNotBlank(issue)) {
                ids.add(new ImmutablePair<String, String>(issue, note));
            }
        }
    }
    return ids;
}

From source file:org.xwiki.pagecreation.internal.PageCreationScriptService.java

/**
 * Private helper to construct the list of arguments based on some parameters.
 * //  w  w  w  .ja v  a2s  .  c o  m
 * @param arguments the XWiki string representation of the arguments
 * @param classDocument the class document of the object to create in the new page
 * @param nameTransformations the transformations to apply to user input
 * @param parameters the parameter map
 * @return the list of java object arguments
 */
private List<Object> getArguments(String[] arguments, DocumentModelBridge classDocument,
        List<String> nameTransformations, Map<String, String[]> parameters) {
    List<Object> args = new ArrayList<Object>();
    for (String argument : arguments) {
        if (argument.startsWith(PROPERTY_ARGUMENT_PREFIX)) {
            String property = StringUtils.substringAfter(argument, PROPERTY_ARGUMENT_PREFIX);
            String key = classDocument.getFullName() + "_0_" + property;
            String input = StringUtils.defaultIfEmpty(parameters.containsKey(key) ? parameters.get(key)[0] : "",
                    "");

            for (String transformation : nameTransformations) {
                if (this.inputTransformers.containsKey(transformation)) {
                    input = this.inputTransformers.get(transformation).transform(input);
                }
            }

            args.add(input);
        } else if (argument.equals(DOCUMENT_ARGUMENT_TITLE)) {
            args.add(parameters.containsKey(TITLE_KEY) ? parameters.get(TITLE_KEY)[0] : "");
        } else if (argument.equals(SPECIAL_ARGUMENT_DATE)) {
            args.add(new Date());
        } else if (argument.equals(SPECIAL_ARGUMENT_COUNTER)) {
            args.add(42);
        }
    }
    return args;
}

From source file:org.xwiki.rendering.test.cts.TestDataParser.java

/**
 * Find {@code *.xml} files in the classpath and return the list of all resources found, without their filename
 * extensions. For example if {@code {ctsDirectoryName}/simple/bold/bold1.*.xml} is found, return
 * {@code simple/bold/bold1}.//www .jav  a 2 s. c  o m
 *
 * @param ctsRootPackageName the root of the CTS resources
 * @param packageFilter the regex to filter packages
 * @param pattern a regex to decide which {@code *.xml} resources should be found. The default should be to find
 *        them all
 * @return the list of relative test directories found
 */
public Set<String> findRelativeTestDirectoryNames(String ctsRootPackageName, String packageFilter,
        String pattern) {
    Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner())
            .setUrls(ClasspathHelper.forPackage(ctsRootPackageName)).filterInputsBy(
                    new FilterBuilder.Include(FilterBuilder.prefix(ctsRootPackageName + DOT + packageFilter))));

    Set<String> prefixes = new TreeSet<String>();
    for (String fullTestDirectoryName : reflections.getResources(Pattern.compile(pattern))) {
        // Remove the prefix and trailing extension
        String testDirectoryName = StringUtils.substringAfter(fullTestDirectoryName,
                ctsRootPackageName + SLASH);
        testDirectoryName = StringUtils.substringBeforeLast(testDirectoryName, ".inout.xml");
        prefixes.add(testDirectoryName);
    }

    return prefixes;
}

From source file:org.xwiki.validator.DutchWebGuidelinesValidator.java

/**
 * Links to e-mail addresses: the e-mail address to which the message is addressed must be visible in the link text.
 *///from  www  . j  a  va 2 s  .com
public void validateRpd8s16() {
    for (Node link : getElements(ELEM_LINK)) {
        String href = getAttributeValue(link, ATTR_HREF);
        if (href != null && href.startsWith(MAILTO)) {
            String email = StringUtils.substringAfter(href, MAILTO);
            assertTrue(Type.ERROR, "rpd8s16.email", link.getTextContent().contains(email));
        }
    }
}

From source file:org.xwiki.validator.DutchWebGuidelinesValidator.java

/**
 * Links to e-mail addresses: the URL in the href attribute of a link to an e-mail address may only contain the
 * mailto protocol and an e-mail address.
 *///from w  w  w.ja  va  2 s  .  co  m
public void validateRpd8s17() {
    for (Node link : getElements(ELEM_LINK)) {
        String href = getAttributeValue(link, ATTR_HREF);
        if (href != null && href.startsWith(MAILTO)) {
            String email = StringUtils.substringAfter(href, MAILTO);
            assertTrue(Type.ERROR, "rpd8s17.email",
                    email.matches("^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[a-zA-Z]{2,4}$"));
        }
    }
}

From source file:org.xwiki.validator.HTML5DutchWebGuidelinesValidator.java

/**
 * Links to e-mail addresses: the e-mail address to which the message is addressed must be visible in the link text.
 *//* w w  w.  j av  a 2s.  c o m*/
public void validateRpd8s16() {
    for (Element link : getElements(ELEM_LINK)) {
        String href = getAttributeValue(link, ATTR_HREF);
        if (href != null && href.startsWith(MAILTO)) {
            String email = StringUtils.substringAfter(href, MAILTO);
            if (email.contains(QUERY_STRING_SEPARATOR)) {
                email = StringUtils.substringBefore(email, QUERY_STRING_SEPARATOR);
            }
            assertTrue(Type.ERROR, "rpd8s16.email", link.text().contains(email));
        }
    }
}

From source file:org.xwiki.validator.HTML5DutchWebGuidelinesValidator.java

/**
 * Links to e-mail addresses: the URL in the href attribute of a link to an e-mail address may only contain the
 * mailto protocol and an e-mail address.
 *///  w ww  . j  a v a 2  s  .  c  o  m
public void validateRpd8s17() {
    for (Element link : getElements(ELEM_LINK)) {
        String href = getAttributeValue(link, ATTR_HREF);
        if (href != null && href.startsWith(MAILTO)) {
            String email = StringUtils.substringAfter(href, MAILTO);
            assertTrue(Type.ERROR, "rpd8s17.email",
                    email.matches("^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[a-zA-Z]{2,4}$"));
        }
    }
}

From source file:org.xwiki.vfs.VfsResourceReference.java

/**
 * @param fullURI the full opaque URI containing both the reference to the archive and the path to the entry inside
 *        it, e.g. {@code attach:space.page@attachment/path/to/file}. Note that this constructor requires that any
 *        "/" character inside the reference to the archive be URL-encoded
 *//*from   ww  w.ja va2s.c o  m*/
public VfsResourceReference(URI fullURI) {
    // Find the first "/" and consider that everything after is the path
    this(URI.create(StringUtils.substringBefore(fullURI.toString(), RESOURCE_PATH_SEPARATOR)),
            StringUtils.substringAfter(fullURI.toString(), RESOURCE_PATH_SEPARATOR));
}

From source file:org.xwiki.webjars.internal.WebJarsExportURLFactoryActionHandler.java

@Override
public URL createURL(String web, String name, String querystring, String anchor, String wikiId,
        XWikiContext context, ExportURLFactoryContext factoryContext) throws Exception {
    // Example of URL:
    // /xwiki/bin/webjars/resources/path?value=bootstrap%2F3.2.0%2Ffonts/glyphicons-halflings-regular.eot
    // where:/*from w  w w .ja  v a2 s  . co m*/
    // - web = resources
    // - name = path
    // - action = webjars
    // - querystring = value=bootstrap%2F3.2.0%2Ffonts/glyphicons-halflings-regular.eot

    // Copy the resources found in JARs on the filesystem

    // We need to decode the passed Query String because the query string passed to ExportURLFactory are always
    // encoded. See XWikiURLFactory#createURL()'s javadoc for more details on why the query string is passed
    // encoded.
    String resourceName = URLDecoder.decode(StringUtils.substringAfter(querystring, "value="), "UTF-8");

    String resourcePath = String.format("%s%s", WEBJARS_RESOURCE_PREFIX, resourceName);

    copyResourceFromJAR(resourcePath, WEBJAR_PATH, factoryContext);

    StringBuffer path = new StringBuffer("file://");

    // Adjust path for links inside CSS files (since they need to be relative to the CSS file they're in).
    factoryContext.adjustCSSPath(path);

    path.append(WEBJAR_PATH);
    path.append(resourcePath.replace(" ", "%20"));
    return new URI(path.toString()).toURL();
}

From source file:org.zht.framework.zhtdao.base.impl.BaseDaoImpl.java

public DataSet loadDataSet(String queryStr, ParamObject paramObject) throws DaoException {
    if (paramObject == null) {
        throw new DaoException("?");
    }/* w  ww . j a va2  s  .c  o m*/
    if (paramObject.getIsNeedCount() == null) {
        throw new DaoException("[NeedCount]?");
    }
    if (paramObject.getIsSql() == null) {
        throw new DaoException("[isSql]?");
    }
    if (paramObject.getIsOffset() == null) {
        throw new DaoException("[isOffset]?");
    }
    if (queryStr == null || !(queryStr.contains("@from") || queryStr.contains("@FROM"))) {
        throw new DaoException("?,[@from]");
    }
    String queryCountStr = " select count(*) from " + StringUtils.substringAfter(queryStr, "@from");
    //?grouby ?
    String countTemp = queryCountStr.replaceAll("\\((.*)\\)", "").replaceAll("[\\s]+", " ").toLowerCase();
    if (countTemp.contains("group by")) {
        queryCountStr = "SELECT count(*) from ( " + queryCountStr + " )";
    }
    queryStr = queryStr.replace("@from", "from").replace("@FROM", "FROM");

    Query queryData, queryCount;
    if (paramObject.getIsSql()) {
        queryData = this.getCurrentSession().createSQLQuery(queryStr)
                .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        queryCount = this.getCurrentSession().createSQLQuery(queryCountStr);
    } else {
        queryData = this.getCurrentSession().createQuery(queryStr)
                .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        queryCount = this.getCurrentSession().createQuery(queryCountStr);
    }

    String tempSql = new String(queryStr);
    Map<String, Object> parmeterSet = paramObject.getQueryParams();
    if (parmeterSet != null && parmeterSet.size() > 0) {
        while (tempSql.contains(":")) {
            tempSql = StringUtils.substringAfter(tempSql, ":");
            String key = StringUtils.substringBefore(tempSql, " ");
            if (key != null && key.trim().endsWith(")")) {
                key = key.replace(")", "");
            }
            if (parmeterSet.keySet().contains(key)) {
                Object paramValue = parmeterSet.get(key);
                //?null////
                if (paramValue == null) {
                    queryData.setParameter(key, paramValue);
                    queryCount.setParameter(key, paramValue);
                } else {
                    if (paramValue instanceof Collection) {
                        queryData.setParameterList(key, (Collection<?>) paramValue);
                        queryCount.setParameterList(key, (Collection<?>) paramValue);
                    } else if (paramValue.getClass().isArray()) {
                        queryData.setParameterList(key, (Object[]) paramValue);
                        queryCount.setParameterList(key, (Object[]) paramValue);
                    } else if ("true".equalsIgnoreCase("" + paramValue)
                            || "false".equalsIgnoreCase("" + paramValue)) {
                        queryData.setParameter(key, Boolean.valueOf("" + paramValue));
                    } else {
                        queryData.setParameter(key, paramValue);
                        queryCount.setParameter(key, paramValue);
                    }
                }

            }
        }
    }

    if (paramObject.getIsOffset()) {
        queryData.setMaxResults(paramObject.getRows());
        queryData.setFirstResult((paramObject.getPage() - 1) * paramObject.getRows());
    }
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> entityList = queryData.list();

    Long total = 0L;
    if (paramObject.getIsNeedCount()) {
        total = (Long) queryCount.uniqueResult();
    }
    return new DataSet(total, entityList);
}