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:com.epam.reportportal.jbehave.JBehaveUtils.java

private static String joinMeta(String key, String value) {
    if (null == value) {
        return key;
    }/*from  w  w w .  ja v a  2s . c o m*/
    if (value.toLowerCase().startsWith("http")) {
        String text;
        if (value.toLowerCase().contains("jira")) {
            text = key + KEY_VALUE_SEPARATOR + StringUtils.substringAfterLast(value, "/");
        } else {
            text = key;
        }
        return wrapAsLink(value, text);
    } else {
        return key + KEY_VALUE_SEPARATOR + value;
    }

}

From source file:info.magnolia.module.admininterface.AdminTreeMVCHandler.java

public Content copyMoveNode(String source, String destination, boolean move)
        throws ExchangeException, RepositoryException {
    // todo: ??? generic -> RequestInterceptor.java
    if (getHierarchyManager().isExist(destination)) {
        String parentPath = StringUtils.substringBeforeLast(destination, "/"); //$NON-NLS-1$
        String label = StringUtils.substringAfterLast(destination, "/"); //$NON-NLS-1$
        label = Path.getUniqueLabel(getHierarchyManager(), parentPath, label);
        destination = parentPath + "/" + label; //$NON-NLS-1$
    }/* w  w  w.ja v a 2  s  . co m*/
    if (move) {
        if (destination.indexOf(source + "/") == 0) { //$NON-NLS-1$
            // todo: disable this possibility in javascript
            // move source into destinatin not possible
            return null;
        }
        this.deActivateNode(source);
        try {
            getHierarchyManager().moveTo(source, destination);
        } catch (Exception e) {
            // try to move below node data
            return null;
        }
    } else {
        // copy
        getHierarchyManager().copyTo(source, destination);
    }
    // SessionAccessControl.invalidateUser(this.getRequest());
    Content newContent = getHierarchyManager().getContent(destination);
    try {
        newContent.updateMetaData();
        newContent.getMetaData().setUnActivated();
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
    }
    newContent.save();
    return newContent;
}

From source file:com.amalto.core.metadata.ClassRepository.java

private String getTypeName(Class clazz) {
    return format(StringUtils.substringAfterLast(clazz.getName(), ".")); //$NON-NLS-1$
}

From source file:com.fortify.bugtracker.common.src.context.AbstractSourceContextGenerator.java

/**
 * Add on-demand data to the given {@link AbstractRestConnectionQueryBuilder}
 * based on {@link ISourceContextGeneratorConfiguration#getExtraData()}.
 * /*w  w w .  jav  a  2  s.c  o m*/
 * @param queryBuilder
 */
private final void addOnDemandData(AbstractRestConnectionQueryBuilder<?, ?> queryBuilder) {
    // TODO Remove code duplication with SourceVulnerabilityProcessorHelper
    Map<String, String> extraData = getConfig().getExtraData();
    if (extraData != null) {
        for (Map.Entry<String, String> entry : extraData.entrySet()) {
            String propertyName = entry.getKey();
            String uriString = StringUtils.substringBeforeLast(entry.getValue(), ";");
            // TODO Parse properly as properties, to allow additional properties if ever necessary
            boolean useCache = "useCache=true".equals(StringUtils.substringAfterLast(entry.getValue(), ";"));
            queryBuilder.onDemand(propertyName, uriString, useCache ? propertyName : null);
        }
    }
}

From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java

private String getRealPropertyName(String propertyName, ResolveAlias ra) {
    if (propertyName.indexOf(".") == -1) {
        //?//from ww  w . ja  va 2 s  . c om
        return propertyName;
    } else {
        //?
        String association = StringUtils.substringBeforeLast(propertyName, ".");
        String property = StringUtils.substringAfterLast(propertyName, ".");
        String aliasName = ra.createAlias(association);
        return aliasName + "." + property;
    }
}

From source file:es.urjc.mctwp.image.impl.dicom.DicomImagePlugin.java

/**
 * Obtains a DICOM representation for single image
 * //from  w  w  w .  j  a va  2 s.  c  om
 * @param single
 * @return
 * @throws ImageException
 */
private List<File> toDicom(SingleImage single, File outputDir) throws ImageException {
    List<File> result = new ArrayList<File>();
    File content = single.getContent();

    try {

        String ext = StringUtils.substringAfterLast(content.getName(), FilenameUtils.EXTENSION_SEPARATOR_STR);
        if (ext == null)
            ext = SingleImageDicomImpl.DCM_EXT;
        File dest = new File(FilenameUtils.concat(outputDir.getAbsolutePath(),
                single.getId() + FilenameUtils.EXTENSION_SEPARATOR_STR + ext));
        FileUtils.copyFile(content, dest);
        result.add(dest);

    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new ImageException(e);
    }

    return result;
}

From source file:edu.ku.brc.af.ui.forms.validation.ValComboBoxFromQuery.java

/**
 * Creates the UI for the ComboBox.//from  ww w .j  a v  a2s .co  m
 * @param objTitle the title of one object needed for the Info Button
 */
public void init(final String objTitle, final int btnMask) {
    fieldNames = split(StringUtils.deleteWhitespace(keyName), ",");

    // strip off any table prefixes
    for (int i = 0; i < fieldNames.length; i++) {
        String fName = fieldNames[i];
        if (fName.indexOf('.') > -1) {
            fieldNames[i] = StringUtils.substringAfterLast(fName, ".");
        }
    }

    boolean hasSearchDlg = StringUtils.isNotEmpty(tableInfo.getSearchDialog());
    boolean hasSearchBtn = (btnMask & CREATE_SEARCH_BTN) != 0;
    boolean hasCloneBtn = (btnMask & CREATE_CLONE_BTN) != 0;
    boolean hasEditBtn = (btnMask & CREATE_EDIT_BTN) != 0;
    boolean hasAddBtn = (btnMask & CREATE_NEW_BTN) != 0;
    final boolean hasViewBtn = (btnMask & CREATE_VIEW_BTN) != 0;

    StringBuilder sb = new StringBuilder("p:g,1px,p,1px,p");
    if (hasSearchDlg) {
        sb.append(",1px,p");
    }
    if (hasCloneBtn) {
        sb.append(",1px,p");
    }
    PanelBuilder pb = new PanelBuilder(new FormLayout(sb.toString(), "c:p"), this);
    CellConstraints cc = new CellConstraints();

    pb.add(textWithQuery, cc.xy(1, 1));

    PermissionSettings perm = AppContextMgr.isSecurityOn() ? tableInfo.getPermissions() : null;

    int x = 3;
    if (hasEditBtn || hasViewBtn) {
        String iconName;
        String ttName;
        if (hasEditBtn && (perm == null || perm.canModify())) {
            iconName = "EditIcon";
            ttName = "EditRecordTT";

        } else {
            iconName = "InfoIcon";
            ttName = "ShowRecordInfoTT";
        }

        editBtn = createBtn(iconName, ttName, objTitle);
        pb.add(editBtn, cc.xy(x, 1));
        x += 2;
    }

    if (hasAddBtn && (perm == null || perm.canAdd())) {
        createBtn = createBtn("CreateObj", "NewRecordTT", objTitle);
        pb.add(createBtn, cc.xy(x, 1));
        x += 2;
    }

    if (hasCloneBtn && (perm == null || perm.canAdd())) {
        cloneBtn = createBtn("CloneObj", "CloneRecordTT", objTitle);
        pb.add(cloneBtn, cc.xy(x, 1));
        x += 2;
    }

    if (hasSearchDlg && hasSearchBtn && (perm == null || perm.canAdd())) {
        textWithQuery.setAddAddItem(hasAddBtn); // set to true if there is an add btn
        searchBtn = createBtn("Search", "SearchForRecordTT", objTitle);
        pb.add(searchBtn, cc.xy(x, 1));
        x += 2;
    }

    if (!UIHelper.isMacOS()) {
        setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    }

    bgColor = textWithQuery.getTextField().getBackground();
    if (valTextColor == null || requiredFieldColor == null) {
        valTextColor = AppPrefsCache.getColorWrapper("ui.formatting.valtextcolor");
        requiredFieldColor = AppPrefsCache.getColorWrapper("ui.formatting.requiredfieldcolor");
    }

    AppPrefsCache.addChangeListener("ui.formatting.requiredfieldcolor", this);

    if (searchBtn != null) {
        defaultSearchAction = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                displaySearchDialog();
            }
        };
        searchBtn.addActionListener(defaultSearchAction);
    }

    if (editBtn != null) {
        defaultEditAction = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                currentMode = MODE.Editting;
                createEditFrame(false, false, hasViewBtn);
            }
        };
        editBtn.addActionListener(defaultEditAction);
    }

    if (createBtn != null) {
        defaultNewAction = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                doNewAction(null);
            }
        };
        createBtn.addActionListener(defaultNewAction);
    }

    if (cloneBtn != null) {
        defaultCloneAction = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dataObj = (FormDataObjIFace) ValComboBoxFromQuery.this.getValue();
                currentMode = MODE.NewAndNotEmpty;
                createEditFrame(true, true, false);
            }
        };
        cloneBtn.addActionListener(defaultCloneAction);
    }
}

From source file:com.hcc.cms.util.PageUtils.java

/**
 * <p>/*from  w w w  . ja  va2  s  . c  o  m*/
 * Responsible for reading the node name from the node path. The underlying
 * implmentation is that the node path always has <code>/</code> as the path
 * separator and this separator is never allows in the paths.
 * </p>
 * <p/>
 * <p>
 * Also, the logic is build on the implementation that any name after the
 * last <code>/</code> will be the node name.
 * </p>
 *
 * @param nodePath
 *            - path of the node
 * @return - node name post substring
 */
public static String getNodeName(final String nodePath) {
    return StringUtils.substringAfterLast(nodePath, SEPARATOR);
}

From source file:eionet.gdem.dcm.business.QAScriptManager.java

/**
 * Add a new QA script into the repository
 *
 * @param user logged in user name.//from   w w w. j a  v  a  2s  .com
 * @param shortName QA script short name.
 * @param schemaId XML Schema Id.
 * @param resultType QA script execution result type (XML, HTML, ...).
 * @param description QA script textual description.
 * @param scriptType QA script type (XQUERY, XSL, XGAWK).
 * @param schema Schema
 * @param scriptFile QA script file
 * @return Script id
 * @throws DCMException If an error occurs.
 */
public String add(String user, String shortName, String schemaId, String schema, String resultType,
        String description, String scriptType, FormFile scriptFile, String upperLimit, String url)
        throws DCMException {

    String scriptId = null;
    // If remote file URL and local file are specified use local file

    try {
        if (!SecurityUtil.hasPerm(user, "/" + Names.ACL_QUERIES_PATH, "i")) {
            LOGGER.debug("You don't have permissions to insert QA script!");
            throw new DCMException(BusinessConstants.EXCEPTION_AUTORIZATION_QASCRIPT_INSERT);
        }
    } catch (DCMException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("Error deleting QA script", e);
        throw new DCMException(BusinessConstants.EXCEPTION_GENERAL);
    }

    boolean useLocalFile = !Utils.isNullStr(scriptFile.getFileName());
    try {
        String fileName = "";
        if (useLocalFile) {
            fileName = scriptFile.getFileName().trim();
        } else {
            fileName = StringUtils.substringAfterLast(url, "/");
        }
        // upload file
        if (!Utils.isNullStr(fileName)) {
            // check if file exists
            if (fileExists(fileName)) {
                throw new DCMException((useLocalFile ? BusinessConstants.EXCEPTION_QASCRIPT_FILE_EXISTS
                        : BusinessConstants.EXCEPTION_QAREMOTESCRIPT_FILE_EXISTS));
            }
        }
        if (Utils.isNullStr(schemaId) || "0".equals(schemaId)) {
            schemaId = schemaDao.getSchemaID(schema);
            if (Utils.isNullStr(schemaId) || "0".equals(schemaId)) {
                schemaId = schemaDao.addSchema(schema, null);
            }
        }

        scriptId = queryDao.addQuery(schemaId, shortName, fileName, description, resultType, scriptType,
                upperLimit, url);
        if (useLocalFile) {
            storeQAScriptFile(scriptFile, fileName);
        } else {
            // If the script type is 'FME' there is no file to download
            if (!XQScript.SCRIPT_LANG_FME.equals(scriptType)) {
                replaceScriptFromRemoteFile(user, url, fileName);
            }
        }
    } catch (DCMException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.error("Error updating QA script", e);
        throw new DCMException(BusinessConstants.EXCEPTION_GENERAL);
    }
    return scriptId;
}

From source file:io.ecarf.core.utils.LogParser.java

/**
 * // ww w  .jav  a2s .c  om
 * @throws FileNotFoundException
 * @throws IOException
 */
private void parse() throws FileNotFoundException, IOException {
    System.out.println("Parsing log files: ");

    for (String file : files) {

        boolean coordinator = file.contains(COORDINATOR);

        Stats stats;
        Stats dStats = null;

        List<Double> bigQuerySave = null;
        List<Double> bigQueryLoad = null;
        List<Double> bigQueryQueriesElapsed = null;

        if (coordinator) {
            stats = new CoordinatorStats();
            this.coordinators.add((CoordinatorStats) stats);

        } else {
            stats = new ProcessorStats();
            this.processors.add((ProcessorStats) stats);
            bigQuerySave = new ArrayList<>();
            bigQueryLoad = new ArrayList<>();
            bigQueryQueriesElapsed = new ArrayList<>();

            dStats = new DictionaryStats();
            dStats.filename = StringUtils.substringAfterLast(file, "/");
            this.dictionaries.add((DictionaryStats) dStats);
        }

        stats.filename = StringUtils.substringAfterLast(file, "/");

        //System.out.println(file);
        String line = null;

        int rows = 0;
        int inferred = 0;

        try (BufferedReader r = new BufferedReader(new FileReader(file))) {
            do {

                line = r.readLine();

                if (line != null) {

                    if (line.indexOf(TIMER) > -1) {
                        this.parseTaskTimer(stats, line, coordinator);

                    } else if (line.indexOf(ELAPSED_JOB) > -1 && coordinator) {
                        ((CoordinatorStats) stats).endToEnd = this.extractAndGetTimer(line, ELAPSED_JOB);

                    } else if (line.indexOf(REASON_TASK_SUMMARY) > -1) {
                        this.extractProcessorReasoningStats(line, (ProcessorStats) stats);

                    } else if (line.indexOf(BIGQUERY_SAVE) > -1) {
                        bigQuerySave.add(this.extractAndGetTimer(line, BIGQUERY_SAVE, true));

                    } else if (line.contains(BIGQUERY_ROWS)) {

                        rows = Integer.parseInt(StringUtils.substringBetween(line, DOWNLOADING, BIGQUERY_ROWS));

                    } else if (line.indexOf(BIGQUERY_JOB_ELAPSED) > -1) {
                        double value = this.extractAndGetTimer(line, BIGQUERY_JOB_ELAPSED, true);
                        r.readLine();
                        String line1 = r.readLine();
                        if (line1 != null && line1.indexOf("\"configuration\" : {") > -1) {

                            line1 = r.readLine();

                            if (line1.indexOf("\"load\" : {") > -1) {
                                bigQueryLoad.add(value);

                                if (inferred > 0) {
                                    this.bigQueryImport.add(new Rows(inferred, value));
                                    inferred = 0;
                                }

                            } else if (line1.indexOf("\"query\" : {") > -1) {

                                // fast forward to this line
                                //"recordsWritten" : "0",

                                do {
                                    line1 = r.readLine();
                                } while (line1 != null && !line1.contains("\"recordsWritten\" :"));

                                if (line1 != null && !line1.contains("\"recordsWritten\" : \"0\",")) {

                                    if (value > 0) {
                                        bigQueryQueriesElapsed.add(value);
                                    }
                                }

                            } else if (line1.indexOf("\"extract\" : {") > -1) {

                                if (rows > 0) {
                                    this.bigQueryExport.add(new Rows(rows, value));
                                    rows = 0;
                                }
                            }
                        }
                    } else if (line.indexOf(ASSEMBLE_DICTIONARY_SUBTASK) > -1
                            || line.contains(ASSEMBLE_DICT_TASK) || line.contains(TERM_DICT_CON)
                            || line.contains(TERM_DICT)) {
                        this.extractDictionaryStats((DictionaryStats) dStats, line);

                    } else if (coordinator) {
                        if (line.contains(JSON_NUM_VM)) {
                            //"numberOfProcessors": 8.0
                            ((CoordinatorStats) stats).numOfProcessors = (int) Double
                                    .parseDouble(StringUtils.substringAfter(line, JSON_NUM_VM + " "));

                        } else if (line.contains(JSON_VM_TYPE)) {
                            //"vmType": "n1-standard-2",
                            ((CoordinatorStats) stats).vmType = StringUtils.substringBetween(line,
                                    JSON_VM_TYPE + " \"", "\",");
                        }

                    } else if (!coordinator && line.contains(FILE_ITEMS)) {
                        // line occurs twice per file, so only add if hasn't been added yet
                        if (((ProcessorStats) stats).fileItems.isEmpty()) {
                            String items = StringUtils.substringAfter(line, FILE_ITEMS);
                            //processor.files.ProcessFilesTask - Processing files: [revision_ids_en.nt.gz, revision_uris_en.nt.gz, yago_taxonomy.nt.gz, interlanguage_links_chapters_en.nt.gz, geo_coordinates_en.nt.gz]
                            List<String> fileItems = Lists
                                    .newArrayList(StringUtils.substringBetween(items, "[", "]").split(", "));
                            ((ProcessorStats) stats).fileItems.addAll(fileItems);
                        }

                    } else if (line.contains(DICT_DOWNLOAD)) {
                        //task.processor.ProcessLoadTask - Loading the dictionary from file: /tmp/dbpedia_dictionary.kryo.gz, memory usage: 1.8702433556318283GB, timer: 9.671 s
                        ((ProcessorStats) stats).dictionaryDowload = this.extractAndGetTimer(line, TIMER_PREFIX,
                                true);
                        double[] values = this.extractAndGetMemoryDictionaryItems(line);
                        ((ProcessorStats) stats).dictionaryMemBefore = values[0];

                    } else if (line.contains(DICT_LOAD)) {
                        //task.processor.ProcessLoadTask - Dictionary loaded successfully, memory usage: 3.9780617877840996GB, timer: 1.160 min
                        ((ProcessorStats) stats).dictionaryLoad = this.extractAndGetTimer(line, TIMER_PREFIX);
                        double[] values = this.extractAndGetMemoryDictionaryItems(line);
                        ((ProcessorStats) stats).dictionaryMemAfter = values[0];
                    }

                    if (line.contains(BIGQUERY_INF)) {
                        //System.out.println(line);
                        if (line.contains("DoReasonTask8")) {
                            inferred = Integer
                                    .parseInt(StringUtils.substringBetween(line, INSERTING8, BIGQUERY_INF));
                        } else {
                            inferred = Integer
                                    .parseInt(StringUtils.substringBetween(line, INSERTING, BIGQUERY_INF));
                        }

                    }

                }

            } while (line != null);
        }

        if (!coordinator) {
            ((ProcessorStats) stats).bigQuerySave = this.sum(bigQuerySave);
            ((ProcessorStats) stats).bigQueryInsert = this.sum(bigQueryLoad);
            if (!bigQueryQueriesElapsed.isEmpty()) {
                ((ProcessorStats) stats).bigQueryAverageQuery = this.sum(bigQueryQueriesElapsed)
                        / bigQueryQueriesElapsed.size();
            }
        }

    }

    //if(!this.jobElapsedTimes.isEmpty()) {
    //   this.coordinators.get(0).endToEnd = this.jobElapsedTimes.get(this.jobElapsedTimes.size() - 1);
    //}

}