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

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

Introduction

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

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:edu.mayo.cts2.framework.plugin.service.bprdf.profile.codesystemversion.BioportalRdfCodeSystemVersionReadService.java

@Override
public CodeSystemVersionCatalogEntry read(NameOrURI identifier, ResolvedReadContext readContext) {

    if (StringUtils.isNotBlank(identifier.getName())) {
        CodeSystemVersionName name = CodeSystemVersionName.parse(identifier.getName());

        String ontologyId = this.idService.getOntologyIdForId(name.getId());

        if (StringUtils.isBlank(ontologyId)) {
            //not found
            return null;
        }//from  ww  w.jav a2s  .  c  o  m

        //check that the acronym part is valid
        CodeSystemVersionName csvCheck = this.idService.getCodeSystemVersionNameForId(name.getId());
        if (csvCheck == null || !name.equals(csvCheck)) {
            //mismatch. this can happen if the user passes in
            //SOMECS__INVALID__-90090, as the first CodeSystemVersionName
            //is initially queried only by the id part
            return null;
        }

        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("id", name.getId());
        parameters.put("ontologyId", ontologyId);

        return this.rdfDao.selectForObject(CODESYSTEMVERSION_NAMESPACE, GET_CODESYSTEMVERSION_BY_NAME,
                parameters, CodeSystemVersionCatalogEntry.class);
    } else {
        String id = StringUtils.substringAfterLast(identifier.getUri(), "/");
        String ontologyId = this.idService.getOntologyIdForId(id);

        if (StringUtils.isBlank(ontologyId)) {
            //no ontologyId found -- means an invalid id
            return null;
        }

        Map<String, Object> parameters = new HashMap<String, Object>();

        parameters.put("ontologyId", ontologyId);
        parameters.put("id", id);

        return this.rdfDao.selectForObject(CODESYSTEMVERSION_NAMESPACE, GET_CODESYSTEMVERSION_BY_URI,
                parameters, CodeSystemVersionCatalogEntry.class);
    }
}

From source file:info.magnolia.cms.beans.config.MIMEMapping.java

/**
 * Get MIME type String.//from   w  w w .  j a  v a2 s.  c  om
 * @param request
 * @return MIME type
 */
public static String getMIMEType(HttpServletRequest request) {
    String extension = (String) request.getAttribute(Aggregator.EXTENSION);
    if (StringUtils.isEmpty(extension)) {
        // the . could be in the middle of the url
        extension = StringUtils.substringAfterLast(request.getRequestURI(), "/");
        extension = StringUtils.substringAfterLast(extension, "."); //$NON-NLS-1$
        if (StringUtils.isEmpty(extension)) {
            extension = Server.getDefaultExtension();
        }
    }
    String mimeType = getMIMEType(extension);

    if (mimeType == null && StringUtils.isNotEmpty(extension)) {
        log.info("Cannot find MIME type for extension \"" + extension + "\""); //$NON-NLS-1$ //$NON-NLS-2$
        mimeType = ((MIMEMappingItem) MIMEMapping.cachedContent.get(Server.getDefaultExtension())).mime;
    }
    return mimeType;
}

From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.MovingFolder.java

protected boolean createFolderNode(String folderPath, ResourceResolver r)
        throws RepositoryException, PersistenceException {
    Session s = r.adaptTo(Session.class);
    if (s.nodeExists(folderPath)) {
        return false;
    }//from   ww  w.  ja  v  a2 s .c o  m

    String name = StringUtils.substringAfterLast(folderPath, "/");
    String parentPath = StringUtils.substringBeforeLast(folderPath, "/");
    createFolderNode(parentPath, r);

    s.getNode(parentPath).addNode(name, DEFAULT_FOLDER_TYPE);
    r.commit();
    r.refresh();
    return true;
}

From source file:edu.ku.brc.af.ui.db.ERTICaptionInfo.java

/**
 * Constructor. Position Index is set after object is created.
 * @param element//from  ww  w .  ja  v a2s.c  o  m
 */
public ERTICaptionInfo(final Element element, final ResourceBundle resBundle) {
    super();

    int tblId = getAttr(element, "tableid", -1); //$NON-NLS-1$
    if (tblId == -1) {
        throw new RuntimeException(
                "search_config.xml caption has bad id[" + getAttr(element, "tableid", "N/A") + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    }

    DBTableInfo tableInfo = DBTableIdMgr.getInstance().getInfoById(tblId);

    String dataObjFormatterName = getAttr(element, "dataobjformatter", null); //$NON-NLS-1$
    String formatter = getAttr(element, "formatter", dataObjFormatterName); //$NON-NLS-1$

    this.colName = element.attributeValue("col"); //$NON-NLS-1$

    String lookupColName = null;
    if (this.colName != null) {
        if (this.colName.indexOf('.') > -1) {
            lookupColName = StringUtils.substringAfterLast(this.colName, ".");
        } else {
            lookupColName = this.colName;
        }
        fieldInfo = tableInfo.getFieldByColumnName(lookupColName);
    }

    String key = getAttr(element, "key", null); //$NON-NLS-1$
    if (StringUtils.isNotEmpty(key)) {
        try {
            colLabel = resBundle.getString(key);
            description = resBundle.getString(key + "_desc"); //$NON-NLS-1$

        } catch (java.util.MissingResourceException ex) {
            log.error("Missing resource [" + key + "] or [" + key + "_desc]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            colLabel = key;
            description = key + "_desc"; //$NON-NLS-1$
        }

    } else if (tableInfo != null) {
        if (fieldInfo == null) {
            if (this.colName != null && this.colName.endsWith("ID")) //$NON-NLS-1$
            {
                colLabel = this.colName;
                description = ""; //$NON-NLS-1$

            } else if (this.colName == null) {
                colInfoList = new Vector<ColInfo>();
                int pos = 0;
                for (Object colObj : element.selectNodes("col")) //$NON-NLS-1$
                {
                    Element colInfoObj = (Element) colObj;
                    ColInfo columnInfo = new ColInfo(getAttr(colInfoObj, "name", null), //$NON-NLS-1$
                            getAttr(colInfoObj, "field", null)); //$NON-NLS-1$
                    columnInfo.setPosition(pos++);
                    if (colInfoList.size() == 0) {
                        fieldInfo = tableInfo.getFieldByColumnName(columnInfo.getColumnName());
                    }
                    colInfoList.add(columnInfo);
                }

                if (tableInfo != null) {
                    for (ColInfo columnInfo : colInfoList) {
                        DBFieldInfo fi = tableInfo.getFieldByName(columnInfo.getFieldName());
                        if (fi != null) {
                            columnInfo.setFieldClass(fi.getDataClass());
                        } else {
                            log.error("Field Name in TableId doesn't exist Class is not a Data Table[" //$NON-NLS-1$
                                    + tableInfo.getTitle() + "] Field[" + columnInfo.getFieldName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                        }
                    }

                } else {
                    log.error("Aggregate Sub Class is not a Data Table[" //$NON-NLS-1$
                            + (tableInfo != null ? tableInfo.getTitle() : "N/A") + "]"); //$NON-NLS-1$
                }

            } else {
                throw new RuntimeException("Couldn't convert column Name[" + this.colName //$NON-NLS-1$
                        + "] to a field name to find the field in table[" + tblId + "]"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        } else if (fieldInfo.getFormatter() != null) {
            formatter = fieldInfo.getFormatter().getName();
        }

    } else {
        throw new RuntimeException("Table Id is bad id[" + getAttr(element, "tableid", "N/A") + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    }

    this.isVisible = getAttr(element, "visible", true); //$NON-NLS-1$

    String aggTableClassName = null;

    Element subElement = (Element) element.selectSingleNode("subobject"); //$NON-NLS-1$

    Element aggElement = (Element) element.selectSingleNode("agg"); //$NON-NLS-1$
    if (aggElement != null) {
        String aggClassName = getAttr(aggElement, "class", null); //$NON-NLS-1$
        if (StringUtils.isNotEmpty(aggClassName)) {
            aggTableClassName = aggClassName;
            try {
                aggClass = Class.forName(aggClassName);
                boolean aggOK = false;
                DBTableInfo tInfo = DBTableIdMgr.getInstance().getByShortClassName(aggClass.getSimpleName());
                if (tInfo != null && StringUtils.isNotEmpty(tInfo.getAggregatorName())) {
                    DataObjAggregator agg = DataObjFieldFormatMgr.getInstance()
                            .getAggregator(tInfo.getAggregatorName());
                    if (agg != null) {
                        aggregatorName = tInfo.getAggregatorName();
                        aggOK = true;
                    }
                }
                if (!aggOK) {
                    aggregatorName = getAttr(aggElement, "aggregator", null); //$NON-NLS-1$
                }
                orderCol = getAttr(aggElement, "ordercol", null); //$NON-NLS-1$

            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERTICaptionInfo.class, ex);
            }
        }
    }

    if (subElement != null) {
        String subClassName = getAttr(subElement, "class", null); //$NON-NLS-1$
        if (StringUtils.isNotEmpty(subClassName)) {
            try {
                subClass = Class.forName(subClassName);
                subClassFieldName = getAttr(subElement, "fieldname", null); //$NON-NLS-1$
                aggTableClassName = subClassName;

            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERTICaptionInfo.class, ex);
            }
        }
    }

    String compositeClassName = null;
    if (StringUtils.isNotEmpty(aggTableClassName)) {
        compositeClassName = aggTableClassName;

    } else if (StringUtils.isNotEmpty(dataObjFormatterName)) {
        dataObjFormatter = DataObjFieldFormatMgr.getInstance().getFormatter(dataObjFormatterName);
        if (dataObjFormatter != null) {
            compositeClassName = dataObjFormatter.getDataClass().getName();
            try {
                aggClass = Class.forName(compositeClassName);

            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERTICaptionInfo.class, ex);
            }
        } else {
            log.error("Couldn't find formatter[" + dataObjFormatterName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        formatter = null;
    }

    if (StringUtils.isNotEmpty(compositeClassName)) {
        colInfoList = new Vector<ColInfo>();
        for (Object colObj : element.selectNodes("col")) //$NON-NLS-1$
        {
            Element colInfoObj = (Element) colObj;
            ColInfo columnInfo = new ColInfo(getAttr(colInfoObj, "name", null), //$NON-NLS-1$
                    getAttr(colInfoObj, "field", null)); //$NON-NLS-1$
            colInfoList.add(columnInfo);
        }

        DBTableInfo ti = DBTableIdMgr.getInstance().getByClassName(compositeClassName);
        if (ti != null) {
            for (ColInfo columnInfo : colInfoList) {
                DBFieldInfo fi = ti.getFieldByName(columnInfo.getFieldName());
                if (fi != null) {
                    columnInfo.setFieldClass(fi.getDataClass());
                } else {
                    log.error("Field Name is Aggregate Sub Class doesn't exist Class is not a Data Table[" //$NON-NLS-1$
                            + compositeClassName + "] Field[" + columnInfo.getFieldName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                }
            }

        } else {
            log.error("Aggregate Sub Class is not a Data Table[" + compositeClassName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    if (StringUtils.isNotEmpty(formatter)) {
        uiFieldFormatter = UIFieldFormatterMgr.getInstance().getFormatter(formatter);
        if (uiFieldFormatter == null) {
            log.error("The UIFieldFormatter could not be found named [" + formatter + "]"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
}

From source file:info.magnolia.importexport.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>some/path/node.prop</code> or <code>some/path/node.@type</code>.
 *//*from   www . j  a va 2  s . c o m*/
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;

        //if this is a node definition (no property)
        String newKey = orgKey;

        // make sure we have a dot as a property separator
        newKey = StringUtils.replace(newKey, "@", ".@");
        // avoid double dots
        newKey = StringUtils.replace(newKey, "..@", ".@");

        String propertyName = StringUtils.substringAfterLast(newKey, ".");
        String keySuffix = StringUtils.substringBeforeLast(newKey, ".");
        String path = StringUtils.replace(keySuffix, ".", "/");
        path = StringUtils.removeStart(path, "/");

        // if this is a path (no property)
        if (StringUtils.isEmpty(propertyName)) {
            // no value --> is a node
            if (StringUtils.isEmpty(properties.getProperty(orgKey))) {
                // make this the type property if not defined otherwise
                if (!properties.containsKey(orgKey + "@type")) {
                    cleaned.put(path + ".@type", ItemType.CONTENTNODE.getSystemName());
                }
                continue;
            }
            propertyName = StringUtils.substringAfterLast(path, "/");
            path = StringUtils.substringBeforeLast(path, "/");
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:com.qualitesys.sonarqcr4pblplugin.pbl.PblFile.java

/**
 * Creates a {@link PblFile} from a file in the source directories.
 *
 * @param unitTest whether it is a unit test file or a source file
 * @return the {@link PblFile} created if exists, null otherwise
 *///from   w  w  w .  j  a  v  a 2 s  .c o m
public static PblFile fromIOFile(File file, List<File> sourceDirs, boolean unitTest) {
    if (file == null) {
        return null;
    }
    //System.out.println("PblFile fromIOFile file "+file+" sourceDirs "+sourceDirs.toString());
    String relativePath = DefaultProjectFileSystem.getRelativePath(file, sourceDirs);
    if (relativePath != null) {
        String pacname = null;
        String classname = relativePath;

        if (relativePath.indexOf('/') >= 0) {
            pacname = StringUtils.substringBeforeLast(relativePath, "/");
            pacname = StringUtils.replace(pacname, "/", ".");
            classname = StringUtils.substringAfterLast(relativePath, "/");
        }
        // Modif D.C. 01 11 2010 en Pb deux fichiers peuvent avoir le meme nom
        // et des extensions differentes. On garde l'extension
        //classname = StringUtils.substringBeforeLast(classname, ".");
        return new PblFile(pacname, classname, unitTest);
    }
    return null;
}

From source file:hudson.plugins.sonar.client.SQProjectResolver.java

static String extractProjectKey(String url) {
    return StringUtils.substringAfterLast(url, "/dashboard/index/");
}

From source file:ch.algotrader.esper.SpringServiceResolver.java

@Override
public void resolve(final EPStatement statement, final String subscriberExpression) {

    if (StringUtils.isBlank(subscriberExpression)) {
        throw new IllegalArgumentException("Subscriber is empty");
    }/*  www  .  j  a v  a2s  .co  m*/

    PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("${", "}", ",", false);
    String s = placeholderHelper.replacePlaceholders(subscriberExpression, name -> {
        if (name.equalsIgnoreCase("strategyName")) {
            return this.strategyName;
        } else {
            return this.configParams.getString(name, "null");
        }
    });

    final Matcher matcher = SUBSCRIBER_NOTATION.matcher(s);
    if (matcher.matches()) {
        // New subscriber notation
        final String beanName = matcher.group(1);
        final String beanMethod = matcher.group(3);
        Object bean = this.applicationContext.getBean(beanName);
        try {
            statement.setSubscriber(bean, beanMethod);
        } catch (EPSubscriberException ex) {
            throw new SubscriberResolutionException("Subscriber expression '" + subscriberExpression
                    + "' could not be resolved to a service method", ex);
        }
    } else {
        // Assuming to be a fully qualified class name otherwise
        try {
            Class<?> cl = Class.forName(s);
            statement.setSubscriber(cl.newInstance());
        } catch (Exception e) {
            // Old notation for backward compatibility
            String serviceName = StringUtils.substringBeforeLast(s, ".");
            if (serviceName.contains(".")) {
                serviceName = StringUtils.remove(StringUtils.remove(
                        StringUtils.uncapitalize(StringUtils.substringAfterLast(serviceName, ".")), "Base"),
                        "Impl");
            }
            String beanMethod = StringUtils.substringAfterLast(s, ".");
            Object bean = this.applicationContext.getBean(serviceName);
            statement.setSubscriber(bean, beanMethod);
        }
    }
}

From source file:edu.monash.merc.system.parser.gpm.GPMRSSReader.java

private GPMSyndEntry createGPMSyndEntry(String ftpLink, Date publishedDate) {
    if (publishedDate == null) {
        return null;
    }// ww w . j  a v a2s .  co  m

    if (StringUtils.isBlank(ftpLink)) {
        return null;
    }

    GPMSyndEntry gpmSyndEntry = new GPMSyndEntry();
    gpmSyndEntry.setReleasedTime(publishedDate);

    String tmpFtpDir = StringUtils.substringBeforeLast(ftpLink, PATH_SEPARATOR);
    String ftpPath = StringUtils.substringAfter(tmpFtpDir, FTP_PROTOCOL);
    String ftpServerName = StringUtils.substringBefore(ftpPath, PATH_SEPARATOR);
    String workdir = StringUtils.substringAfter(ftpPath, PATH_SEPARATOR);
    String fileName = StringUtils.substringAfterLast(ftpLink, PATH_SEPARATOR);
    gpmSyndEntry.setGmpFtpServer(ftpServerName);
    gpmSyndEntry.setTpbWorkDir(PATH_SEPARATOR + workdir);
    gpmSyndEntry.setReleasedTpbFileName(fileName);
    return gpmSyndEntry;
}

From source file:com.jaxio.celerio.model.support.search.SearchAttribute.java

public String getFieldBridgeAnnotation() {
    IndexedField field = attribute.getColumnConfig().getIndexedField();
    if (field == null || !field.hasBridgeImpl()) {
        return "";
    }//  w  w w  .  j  a  v  a 2  s  . c  o m

    addImport("org.hibernate.search.annotations.FieldBridge");
    addImport(field.getBridgeImpl());
    String type = StringUtils.substringAfterLast(field.getBridgeImpl(), ".");
    return "@FieldBridge(impl = " + type + ".class)";
}