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

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

Introduction

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

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:info.magnolia.cms.util.ClasspathResourcesUtil.java

/**
 * Load resources from jars or directories
 *
 * @param resources found resources will be added to this collection
 * @param jarOrDir  a File, can be a jar or a directory
 * @param filter    used to filter resources
 *///www. j ava 2  s  .com
private static void collectFiles(Collection resources, File jarOrDir, Filter filter) {

    if (!jarOrDir.exists()) {
        log.warn("missing file: {}", jarOrDir.getAbsolutePath());
        return;
    }

    if (jarOrDir.isDirectory()) {
        if (log.isDebugEnabled())
            log.debug("looking in dir {}", jarOrDir.getAbsolutePath());

        Collection files = FileUtils.listFiles(jarOrDir, new TrueFileFilter() {
        }, new TrueFileFilter() {
        });
        for (Iterator iter = files.iterator(); iter.hasNext();) {
            File file = (File) iter.next();
            String name = StringUtils.substringAfter(file.getPath(), jarOrDir.getPath());

            // please, be kind to Windows!!!
            name = StringUtils.replace(name, "\\", "/");
            if (!name.startsWith("/")) {
                name = "/" + name;
            }

            if (filter.accept(name)) {
                resources.add(name);
            }
        }
    } else if (jarOrDir.getName().endsWith(".jar")) {
        if (log.isDebugEnabled())
            log.debug("looking in jar {}", jarOrDir.getAbsolutePath());
        JarFile jar;
        try {
            jar = new JarFile(jarOrDir);
        } catch (IOException e) {
            log.error("IOException opening file {}, skipping", jarOrDir.getAbsolutePath());
            return;
        }
        for (Enumeration em = jar.entries(); em.hasMoreElements();) {
            JarEntry entry = (JarEntry) em.nextElement();
            if (!entry.isDirectory()) {
                if (filter.accept("/" + entry.getName())) {
                    resources.add("/" + entry.getName());
                }
            }
        }
    } else {
        if (log.isDebugEnabled())
            log.debug("Unknown (not jar) file in classpath: {}, skipping.", jarOrDir.getName());
    }

}

From source file:eionet.cr.dao.virtuoso.PredicateObjectsReader.java

@Override
public void readRow(BindingSet bindingSet) throws ResultSetReaderException {

    Value objectValue = bindingSet.getValue("obj");
    Value objectLabelValue = bindingSet.getValue("objLabel");
    Value graphValue = bindingSet.getValue("g");

    if (objectValue != null) {

        String value = objectValue.stringValue();
        boolean isLiteral = objectValue instanceof Literal;
        boolean isAnonymous = isLiteral ? false : objectValue instanceof BNode;
        if (!isLiteral) {
            value = objectValue.toString();
            if (isAnonymous) {
                value = URIUtil.sanitizeVirtuosoBNodeUri(value);
            }/*  w  ww .  j  a  va  2 s.co m*/
        }

        Literal literal = isLiteral ? (Literal) objectValue : null;
        String language = isLiteral ? literal.getLanguage() : null;

        if (!objectAlreadyAdded(value, isLiteral, language)) {

            URI datatype = isLiteral ? literal.getDatatype() : null;

            ObjectDTO objectDTO = new ObjectDTO(value, language, isLiteral, isAnonymous, datatype);
            if (graphValue != null && graphValue instanceof Resource) {
                objectDTO.setSourceUri(graphValue.stringValue());
            }

            if (objectLabelValue != null && objectLabelValue instanceof Literal) {

                Literal labelLiteral = (Literal) objectLabelValue;
                ObjectDTO labelObjectDTO = new ObjectDTO(labelLiteral.stringValue(), labelLiteral.getLanguage(),
                        true, false);
                objectDTO.setLabelObject(labelObjectDTO);
            } else if (isAnonymous) {
                // For anonymous object resources ensure that there is a label by feeding it via derived label.
                String derivedValue = StringUtils.substringAfter(value, VirtuosoBaseDAO.VIRTUOSO_BNODE_PREFIX);
                objectDTO.setDerviedLiteralValue(derivedValue);
            }

            resultList.add(objectDTO);
            if (isLiteral) {
                HashSet<String> valuesByLang = distinctLiterals.get(language);
                if (valuesByLang == null) {
                    valuesByLang = new HashSet<String>();
                    distinctLiterals.put(language, valuesByLang);
                }
                valuesByLang.add(value);
            } else {
                distinctResources.add(value);
            }
        }
    }
}

From source file:com.safetys.framework.jmesa.worksheet.WorksheetUpdater.java

protected WorksheetRow getWorksheetRow(Worksheet worksheet, WebContext webContext) {
    Map<?, ?> parameters = webContext.getParameterMap();
    for (Object param : parameters.keySet()) {
        String parameter = (String) param;
        if (parameter.startsWith(UNIQUE_PROPERTIES)) {
            String value = webContext.getParameter(parameter);
            String property = StringUtils.substringAfter(parameter, UNIQUE_PROPERTIES);

            UniqueProperty uniqueProperty = new UniqueProperty(property, value);
            WorksheetRow worksheetRow = worksheet.getRow(uniqueProperty);
            if (worksheetRow == null) {
                worksheetRow = new WorksheetRow(uniqueProperty);
                worksheetRow.setRowStatus(WorksheetRowStatus.MODIFY);
                worksheet.addRow(worksheetRow);
            }//from   w ww  .j av a 2s  .  com

            return worksheetRow;
        }
    }

    return null;
}

From source file:jp.techlier.extensions.velocity.directive.DirectiveHelper.java

public String getReferenceName(final Node node) {
    if (node != null) {
        if (node instanceof ASTReference) {
            return ((ASTReference) node).getRootString();
        } else if (node.getType() == ParserTreeConstants.JJTREFERENCE) {
            return StringUtils.substringAfter(node.getFirstToken().image, "$");
        }/*from   w  ww .  ja  v a  2s  .c  o m*/
    }
    return null;
}

From source file:com.netflix.explorers.PropertiesGlobalModelContext.java

public PropertiesGlobalModelContext(Properties props) {
    this.properties = props;

    environmentName = props.getProperty(PROPERTY_ENVIRONMENT_NAME);
    currentRegion = props.getProperty(PROPERTY_CURRENT_REGION);
    applicationVersion = props.getProperty(PROPERTY_APPLICATION_VERSION);
    applicationName = props.getProperty(PROPERTY_APPLICATION_NAME);
    isLocal = Boolean.parseBoolean(props.getProperty(PROPERTY_IS_LOCAL, "false"));
    homePageUrl = props.getProperty(PROPERTY_HOME_PAGE);
    defaultPort = Short.parseShort(props.getProperty(PROPERTY_DEFAULT_PORT, "8080"));
    dataCenter = props.getProperty(PROPERTY_DATA_CENTER);
    defaultExplorerName = props.getProperty(PROPERTY_DEFAULT_EXPLORER);

    try {/*from w w w.  j  a v a 2s.c o  m*/
        Map<Object, Object> dcs = ConfigurationConverter
                .getMap(ConfigurationConverter.getConfiguration(props).subset(PROPERTIES_PREFIX + ".dc"));
        for (Entry<Object, Object> dc : dcs.entrySet()) {
            String key = StringUtils.substringBefore(dc.getKey().toString(), ".");
            String attr = StringUtils.substringAfter(dc.getKey().toString(), ".");

            CrossLink link = links.get(key);
            if (link == null) {
                link = new CrossLink();
                links.put(key, link);
            }

            BeanUtils.setProperty(link, attr, dc.getValue());
        }
    } catch (Exception e) {
        LOG.error("Exception ", e);
        throw new RuntimeException(e);
    }
}

From source file:fr.dutra.tools.maven.deptree.core.AbstractLineBasedParser.java

/**
 * When doing an install at the same time on a multi-module project, one can get this kind of output:
 * <pre>/*from w w w. ja  v a  2  s .c  o  m*/
 * +- active project artifact:
 *     artifact = active project artifact:
 *     artifact = active project artifact:
 *     artifact = active project artifact:
 *     artifact = active project artifact:
 *     artifact = active project artifact:
 *     artifact = active project artifact:
 *     artifact = active project artifact:
 *     artifact = com.acme.org:foobar:jar:1.0.41-SNAPSHOT:compile;
 *     project: MavenProject: com.acme.org:foobar:1.0.41-SNAPSHOT @ /opt/jenkins/home/jobs/foobar/workspace/trunk/foobar/pom.xml;
 *     project: MavenProject: com.acme.org:foobar:1.0.41-SNAPSHOT @ /opt/jenkins/home/jobs/foobar/workspace/trunk/foobar/pom.xml;
 *     project: MavenProject: com.acme.org:foobar:1.0.41-SNAPSHOT @ /opt/jenkins/home/jobs/foobar/workspace/trunk/foobar/pom.xml;
 *     project: MavenProject: com.acme.org:foobar:1.0.41-SNAPSHOT @ /opt/jenkins/home/jobs/foobar/workspace/trunk/foobar/pom.xml;
 *     project: MavenProject: com.acme.org:foobar:1.0.41-SNAPSHOT @ /opt/jenkins/home/jobs/foobar/workspace/trunk/foobar/pom.xml;
 *     project: MavenProject: com.acme.org:foobar:1.0.41-SNAPSHOT @ /opt/jenkins/home/jobs/foobar/workspace/trunk/foobar/pom.xml;
 *     project: MavenProject: com.acme.org:foobar:1.0.41-SNAPSHOT @ /opt/jenkins/home/jobs/foobar/workspace/trunk/foobar/pom.xml;
 *     project: MavenProject: com.acme.org:foobar:1.0.41-SNAPSHOT @ /opt/jenkins/home/jobs/foobar/workspace/trunk/foobar/pom.xml
 * </pre>
 */
protected String extractActiveProjectArtifact() {
    String artifact = null;
    //start at next line and consume all lines containing "artifact =" or "project: "; record the last line containing "artifact =".
    boolean artifactFound = false;
    while (this.lineIndex < this.lines.size() - 1) {
        String tempLine = this.lines.get(this.lineIndex + 1);
        boolean artifactLine = !artifactFound && tempLine.contains("artifact = ");
        boolean projectLine = artifactFound && tempLine.contains("project: ");
        if (artifactLine || projectLine) {
            if (tempLine.contains("artifact = ") && !tempLine.contains("active project artifact:")) {
                artifact = StringUtils.substringBefore(StringUtils.substringAfter(tempLine, "artifact = "),
                        ";");
                artifactFound = true;
            }
            this.lineIndex++;
        } else {
            break;
        }
    }
    return artifact;
}

From source file:com.amalto.core.server.routing.DefaultRoutingEngine.java

/**
 * Check that a rule actually matches a document
 * /*ww  w.j a  va  2  s  .  co m*/
 * @return true if it matches
 * @throws XtentisException
 */
private static boolean ruleExpressionMatches(ItemPOJO itemPOJO, RoutingRuleExpressionPOJO exp)
        throws XtentisException {
    Integer contentInt, expInt;
    String expXpath = exp.getXpath();
    if (expXpath.startsWith(itemPOJO.getConceptName())) {
        expXpath = StringUtils.substringAfter(expXpath, itemPOJO.getConceptName() + '/');
    }
    try {
        String[] contents = Util.getTextNodes(itemPOJO.getProjection(), expXpath);
        if (contents.length == 0 && exp.getOperator() == RoutingRuleExpressionPOJO.IS_NULL) {
            return true;
        }
        boolean match = false;
        for (String content : contents) {
            if (match) {
                break;
            }
            switch (exp.getOperator()) {
            case RoutingRuleExpressionPOJO.CONTAINS:
                match = StringUtils.contains(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.EQUALS:
                match = StringUtils.equals(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.GREATER_THAN:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt > expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.GREATER_THAN_OR_EQUAL:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt >= expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.IS_NOT_NULL:
                match = content != null;
                break;
            case RoutingRuleExpressionPOJO.LOWER_THAN:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt < expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.LOWER_THAN_OR_EQUAL:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt <= expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.MATCHES:
                match = StringUtils.countMatches(content, exp.getValue()) > 0;
                break;
            case RoutingRuleExpressionPOJO.NOT_EQUALS:
                match = !StringUtils.equals(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.STARTSWITH:
                if (content != null) {
                    match = content.startsWith(exp.getValue());
                }
                break;
            }
        }
        return match;
    } catch (TransformerException e) {
        String err = "Subscription rule expression match: unable extract xpath '" + exp.getXpath()
                + "' from Item '" + itemPOJO.getItemPOJOPK().getUniqueID() + "': " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:com.ewcms.component.util.Struts2Util.java

/**
 * ?contentTypeheaders./*from w ww.j a  v a  2s . c  o  m*/
 */
private static HttpServletResponse initResponseHeader(final String contentType, final String... headers) {
    //?headers?
    String encoding = DEFAULT_ENCODING;
    boolean noCache = DEFAULT_NOCACHE;
    for (String header : headers) {
        String headerName = StringUtils.substringBefore(header, ":");
        String headerValue = StringUtils.substringAfter(header, ":");

        if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) {
            encoding = headerValue;
        } else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) {
            noCache = Boolean.parseBoolean(headerValue);
        } else {
            throw new IllegalArgumentException(headerName + "??header");
        }
    }

    HttpServletResponse response = ServletActionContext.getResponse();

    //headers?
    String fullContentType = contentType + ";charset=" + encoding;
    response.setContentType(fullContentType);
    if (noCache) {
        ServletUtil.setNoCacheHeader(response);
    }

    return response;
}

From source file:cool.pandora.modeller.ui.handlers.text.CreateWordsHandler.java

@Override
public void execute() {
    final String message = ApplicationContextUtil.getMessage("bag.message.wordcreated");
    final DefaultBag bag = bagView.getBag();
    final Map<String, BagInfoField> map = bag.getInfo().getFieldMap();
    final String url = bag.gethOCRResource();
    List<String> wordIdList = null;
    try {/*from   w  w w.  j  av a  2 s  .c  o m*/
        final hOCRData hocr = DocManifestBuilder.gethOCRProjectionFromURL(url);
        wordIdList = getWordIdList(hocr);
    } catch (final IOException e) {
        e.printStackTrace();
    }
    assert wordIdList != null;
    for (String resourceID : wordIdList) {
        resourceID = StringUtils.substringAfter(resourceID, "_");
        final URI wordObjectURI = getWordObjectURI(map, resourceID);
        try {
            ModellerClient.doPut(wordObjectURI);
            ApplicationContextUtil.addConsoleMessage(message + " " + wordObjectURI);
        } catch (final ModellerClientFailedException e) {
            ApplicationContextUtil.addConsoleMessage(getMessage(e));
        }
    }
    bagView.getControl().invalidate();
}

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

/**
 * other object compile/*from w  w  w  .ja v  a2  s.  c  o m*/
 * 
 * @param actionType 
 * @param objType
 * @param objName
 * @param userDB
 */
public static String otherObjectCompile(PublicTadpoleDefine.QUERY_DDL_TYPE actionType, String objType,
        String objName, UserDBDAO userDB) throws Exception {
    //  ? DEBUG? ? ? ?.

    //TODO:  DAO? ? ? ??     . 
    Map<String, String> paramMap = new HashMap<String, String>();
    if (StringUtils.contains(objName, '.')) {
        //??   ?? ...
        paramMap.put("schema_name", StringUtils.substringBefore(objName, "."));
        paramMap.put("object_name",
                SQLUtil.makeIdentifierName(userDB, StringUtils.substringAfter(objName, ".")));
        paramMap.put("full_name", SQLUtil.makeIdentifierName(userDB, objName));
    } else {
        //    ?    .
        paramMap.put("schema_name", userDB.getSchema());
        paramMap.put("object_name", SQLUtil.makeIdentifierName(userDB, objName));
        paramMap.put("full_name", userDB.getSchema() + "." + SQLUtil.makeIdentifierName(userDB, objName));
    }
    if (PublicTadpoleDefine.QUERY_DDL_TYPE.JAVA == actionType) {
        //Java object ? ? .
        return otherObjectCompile(actionType, objType, paramMap, userDB, false);
    } else {
        return otherObjectCompile(actionType, objType, paramMap, userDB,
                userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT);
    }
}