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:com.dgq.utils.Struts2Utils.java

/**
 * ?contentTypeheaders./*from w  ww.j  a  v a 2s . c  om*/
 */
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 = getResponse();

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

    return response;
}

From source file:gov.nih.nci.caarray.util.owlparser.AbstractOntologyOwlParser.java

private String getIdentifier(Element e) {
    Attribute id = e.attribute(getIdAttributeName());
    if (id != null) {
        return id.getValue();
    }//from www  .j  a  v a 2  s .  c  o m
    Attribute about = e.attribute(getAboutAttributeName());
    if (about != null) {
        return StringUtils.substringAfter(about.getValue(), FRAGMENT_SEPARATOR);
    }
    Attribute resource = e.attribute(getResourceAttributeName());
    if (resource != null) {
        return StringUtils.substringAfter(resource.getValue(), FRAGMENT_SEPARATOR);
    }
    return null;
}

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

/**
 * @param xmlFile/*w  w  w  .j  av a 2  s .c  om*/
 * @param repositoryName
 * @throws IOException
 */
public static void executeBootstrapImport(File xmlFile, String repositoryName) throws IOException {
    String filenameWithoutExt = StringUtils.substringBeforeLast(xmlFile.getName(), DOT);
    if (filenameWithoutExt.endsWith(XML)) {
        // if file ends in .xml.gz or .xml.zip
        // need to keep the .xml to be able to view it after decompression
        filenameWithoutExt = StringUtils.substringBeforeLast(xmlFile.getName(), DOT);
    }
    String pathName = StringUtils.substringAfter(StringUtils.substringBeforeLast(filenameWithoutExt, DOT), DOT);

    pathName = decodePath(pathName, UTF8);

    String basepath = SLASH + StringUtils.replace(pathName, DOT, SLASH);

    if (xmlFile.getName().endsWith(PROPERTIES)) {
        Properties properties = new Properties();
        FileInputStream stream = new FileInputStream(xmlFile);
        properties.load(stream);
        stream.close();
        importProperties(properties, repositoryName);
    } else {
        DataTransporter.importFile(xmlFile, repositoryName, basepath, false, BOOTSTRAP_IMPORT_MODE, true, true);
    }
}

From source file:edu.cornell.kfs.coa.document.validation.impl.AccountReversionRule.java

/**
 * Validates that the fund group code on the sub fund group on the reversion account is valid as defined by the allowed
 * values in SELECTION_1 system parameter.
 * /*from   w  w  w  . ja v a 2s .co  m*/
 * @param acctReversion
 * @return true if valid, false otherwise
 */
protected boolean validateAccountFundGroup(AccountReversion acctReversion) {
    boolean valid = true;

    String fundGroups = SpringContext.getBean(ParameterService.class).getParameterValueAsString(Reversion.class,
            CUKFSConstants.Reversion.SELECTION_1);
    String propertyName = StringUtils.substringBefore(fundGroups, "=");
    List<String> ruleValues = Arrays.asList(StringUtils.substringAfter(fundGroups, "=").split(";"));

    if (ObjectUtils.isNotNull(ruleValues) && ruleValues.size() > 0) {

        GlobalVariables.getMessageMap().addToErrorPath("document.newMaintainableObject");

        if (ObjectUtils.isNotNull(acctReversion.getAccount())
                && ObjectUtils.isNotNull(acctReversion.getAccount().getSubFundGroup())) {
            String accountFundGroupCode = acctReversion.getAccount().getSubFundGroup().getFundGroupCode();

            if (!ruleValues.contains(accountFundGroupCode)) {
                valid = false;
                GlobalVariables.getMessageMap().putError(CUKFSPropertyConstants.ACCT_REVERSION_ACCT_NUMBER,
                        RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER,
                        new String[] {
                                getDataDictionaryService().getAttributeLabel(FundGroup.class,
                                        KFSPropertyConstants.CODE),
                                accountFundGroupCode,
                                getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_1),
                                getParameterValuesForMessage(ruleValues),
                                getDataDictionaryService().getAttributeLabel(AccountReversion.class,
                                        CUKFSPropertyConstants.ACCT_REVERSION_ACCT_NUMBER) });
            }
        }

        if (ObjectUtils.isNotNull(acctReversion.getBudgetReversionAccount())
                && ObjectUtils.isNotNull(acctReversion.getBudgetReversionAccount().getSubFundGroup())) {
            String budgetAccountFundGroupCode = acctReversion.getBudgetReversionAccount().getSubFundGroup()
                    .getFundGroupCode();

            if (!ruleValues.contains(budgetAccountFundGroupCode)) {
                valid = false;
                GlobalVariables.getMessageMap().putError(
                        CUKFSPropertyConstants.ACCT_REVERSION_BUDGET_REVERSION_ACCT_NUMBER,
                        RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER,
                        new String[] {
                                getDataDictionaryService().getAttributeLabel(FundGroup.class,
                                        KFSPropertyConstants.CODE),
                                budgetAccountFundGroupCode,
                                getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_1),
                                getParameterValuesForMessage(ruleValues),
                                getDataDictionaryService().getAttributeLabel(AccountReversion.class,
                                        CUKFSPropertyConstants.ACCT_REVERSION_BUDGET_REVERSION_ACCT_NUMBER) });
            }
        }

        if (ObjectUtils.isNotNull(acctReversion.getCashReversionAccount())
                && ObjectUtils.isNotNull(acctReversion.getCashReversionAccount().getSubFundGroup())) {
            String cashAccountFundGroupCode = acctReversion.getCashReversionAccount().getSubFundGroup()
                    .getFundGroupCode();

            if (!ruleValues.contains(cashAccountFundGroupCode)) {
                valid = false;
                GlobalVariables.getMessageMap().putError(
                        CUKFSPropertyConstants.ACCT_REVERSION_CASH_REVERSION_ACCT_NUMBER,
                        RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER,
                        new String[] {
                                getDataDictionaryService().getAttributeLabel(FundGroup.class,
                                        KFSPropertyConstants.CODE),
                                cashAccountFundGroupCode,
                                getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_1),
                                getParameterValuesForMessage(ruleValues),
                                getDataDictionaryService().getAttributeLabel(AccountReversion.class,
                                        CUKFSPropertyConstants.ACCT_REVERSION_CASH_REVERSION_ACCT_NUMBER) });
            }
        }

        GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject");
    }
    return valid;
}

From source file:ddf.catalog.source.solr.SolrFilterDelegate.java

private void combineXpathFilterQueries(SolrQuery query, List<SolrQuery> subQueries, String operator) {
    List<String> queryParams = new ArrayList<>();
    // Use Set to remove duplicates now that the namespaces have been stripped out
    Set<String> xpathFilters = new TreeSet<>();
    Set<String> xpathIndexes = new TreeSet<>();

    for (SolrQuery subQuery : subQueries) {
        String[] params = subQuery.getParams(FILTER_QUERY_PARAM_NAME);
        if (params != null) {
            for (String param : params) {
                if (StringUtils.startsWith(param, XPATH_QUERY_PARSER_PREFIX)) {
                    if (StringUtils.contains(param, XPATH_FILTER_QUERY_INDEX)) {
                        xpathIndexes//from ww w  . j av  a  2  s  .  c o m
                                .add(StringUtils.substringAfter(StringUtils.substringBeforeLast(param, "\""),
                                        XPATH_FILTER_QUERY_INDEX + ":\""));
                    } else if (StringUtils.startsWith(param, XPATH_QUERY_PARSER_PREFIX + XPATH_FILTER_QUERY)) {
                        xpathFilters.add(StringUtils.substringAfter(
                                StringUtils.substringBeforeLast(param, "\""), XPATH_FILTER_QUERY + ":\""));
                    }
                }
                Collections.addAll(queryParams, param);
            }
        }
    }

    if (xpathFilters.size() > 1) {
        // More than one XPath found, need to combine
        String filter = XPATH_QUERY_PARSER_PREFIX + XPATH_FILTER_QUERY + ":\"("
                + StringUtils.join(xpathFilters, operator.toLowerCase()) + ")\"";

        List<String> indexes = new ArrayList<>();
        for (String xpath : xpathIndexes) {
            indexes.add("(" + XPATH_FILTER_QUERY_INDEX + ":\"" + xpath + "\")");
        }
        // TODO DDF-1882 add pre-filter xpath index
        //String index = XPATH_QUERY_PARSER_PREFIX + StringUtils.join(indexes, operator);
        //query.setParam(FILTER_QUERY_PARAM_NAME, filter, index);
        query.setParam(FILTER_QUERY_PARAM_NAME, filter);
    } else if (queryParams.size() > 0) {
        // Pass through original filter queries if only a single XPath is present
        query.setParam(FILTER_QUERY_PARAM_NAME, queryParams.toArray(new String[queryParams.size()]));
    }
}

From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java

private void insertDailyPartition(Path dailyPartitionPath) throws Exception {

    String datasetPath = StringUtils.substringBeforeLast(dailyPartitionPath.toString(),
            Path.SEPARATOR + "daily");

    DateTime partition = DateTimeFormat.forPattern(DAILY_PARTITION_PATTERN)
            .parseDateTime(StringUtils.substringAfter(dailyPartitionPath.toString(), "daily" + Path.SEPARATOR));

    PreparedStatement insert = connection.prepareStatement("INSERT INTO Daily_Partitions VALUES (?, ?, ?)");
    insert.setString(1, datasetPath);//from  w w  w .j a va  2s . c  o m
    insert.setString(2, dailyPartitionPath.toString());
    insert.setTimestamp(3, new Timestamp(partition.getMillis()));

    insert.executeUpdate();

}

From source file:com.pieframework.model.repository.ModelStore.java

public static List<ExpressionEntry> parseInstanceFile(File file) throws IOException {
    List<ExpressionEntry> retList = new ArrayList<ExpressionEntry>();
    LineIterator it = FileUtils.lineIterator(file);
    try {//from   ww w .  j  a v a  2s . c  om
        while (it.hasNext()) {
            String line = it.nextLine();
            if (StringUtils.startsWith(line, "#")) {
                // ignore comments
            } else {
                String expression = StringUtils.trimToEmpty(StringUtils.substringBefore(line, "="));
                String value = StringUtils.trimToEmpty(StringUtils.substringAfter(line, "="));
                if (StringUtils.isNotEmpty(expression) && StringUtils.isNotEmpty(value)) {
                    retList.add(new ExpressionEntry().withExpression(expression).withValue(value));
                }
            }
        }
    } finally {
        it.close();
    }
    return retList;
}

From source file:cool.pandora.modeller.ui.handlers.common.NodeMap.java

/**
 * getWordsForPageMap./*  w  w w  .  j  a  v  a 2  s. c  om*/
 *
 * @param hocr       hOCRData
 * @param pageIdList List
 * @return Map
 */
public static Map<String, List<String>> getWordsForPageMap(final hOCRData hocr, final List<String> pageIdList) {
    final Map<String, List<String>> nodemap = new HashMap<>();
    List<String> wordIdList;
    for (String pageId : pageIdList) {
        wordIdList = getWordIdListforPage(hocr, pageId);
        for (int i = 0; i < wordIdList.size(); i++) {
            final String wordId = StringUtils.substringAfter(wordIdList.get(i), "_");
            wordIdList.set(i, wordId);
        }
        pageId = StringUtils.substringAfter(pageId, "_");
        nodemap.put(pageId, wordIdList);
    }
    return nodemap;
}

From source file:ddf.security.samlp.MetadataConfigurationParser.java

private void buildEntityDescriptor(String entityDescription) throws IOException {
    EntityDescriptor entityDescriptor = null;
    entityDescription = entityDescription.trim();
    if (entityDescription.startsWith(HTTPS) || entityDescription.startsWith(HTTP)) {
        if (entityDescription.startsWith(HTTP)) {
            LOGGER.warn(//from   ww  w .  ja  v  a2s . co  m
                    "Retrieving metadata via HTTP instead of HTTPS. The metadata configuration is unsafe!!!");
        }
        HttpTransport httpTransport = new ApacheHttpTransport();
        HttpRequest httpRequest = httpTransport.createRequestFactory()
                .buildGetRequest(new GenericUrl(entityDescription));
        httpRequest.setUnsuccessfulResponseHandler(
                new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff())
                        .setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ALWAYS));
        ListeningExecutorService service = MoreExecutors
                .listeningDecorator(Executors.newSingleThreadExecutor());
        ListenableFuture<HttpResponse> httpResponseFuture = service.submit(httpRequest::execute);

        Futures.addCallback(httpResponseFuture, new FutureCallback<HttpResponse>() {
            @Override
            public void onSuccess(HttpResponse httpResponse) {
                if (httpResponse != null) {
                    try {
                        String parsedResponse = httpResponse.parseAsString();
                        buildEntityDescriptor(parsedResponse);
                    } catch (IOException e) {
                        LOGGER.error("Unable to parse metadata from: {}",
                                httpResponse.getRequest().getUrl().toString(), e);
                    }
                }
            }

            @Override
            public void onFailure(Throwable throwable) {
                LOGGER.error("Unable to retrieve metadata.", throwable);
            }
        });
        service.shutdown();
    } else if (entityDescription.startsWith(FILE + System.getProperty("ddf.home"))) {
        String pathStr = StringUtils.substringAfter(entityDescription, FILE);
        Path path = Paths.get(pathStr);
        if (Files.isReadable(path)) {
            try (InputStream fileInputStream = Files.newInputStream(path)) {
                entityDescriptor = readEntityDescriptor(new InputStreamReader(fileInputStream, "UTF-8"));
            }
        }
    } else if (entityDescription.startsWith("<") && entityDescription.endsWith(">")) {
        entityDescriptor = readEntityDescriptor(new StringReader(entityDescription));
    } else {
        LOGGER.warn("Skipping unknown metadata configuration value: " + entityDescription);
    }

    if (entityDescriptor != null) {
        entityDescriptorMap.put(entityDescriptor.getEntityID(), entityDescriptor);
        if (updateCallback != null) {
            updateCallback.accept(entityDescriptor);
        }
    }
}

From source file:com.doculibre.constellio.lucene.impl.SkosIndexHelperImpl.java

@Override
protected void populateIndexField(SkosConcept skosConcept, Field indexField, Document doc) {
    String indexFieldName = indexField.name();
    List<Locale> supportedLocales = ConstellioSpringUtils.getSupportedLocales();
    if (indexFieldName.equals(ID)) {
        indexField.setStringValue(skosConcept.getId().toString());
    } else if (indexFieldName.equals(THESAURUS_ID)) {
        indexField.setStringValue(skosConcept.getThesaurus().getId().toString());
    } else if (indexFieldName.equals(PREF_LABEL)) {
        boolean first = true;
        for (I18NLabel prefLabel : skosConcept.getPrefLabels()) {
            for (Locale locale : prefLabel.getValues().keySet()) {
                if (supportedLocales.contains(locale)) {
                    if (first) {
                        indexField.setStringValue(prefLabel.getValue(locale));
                        first = false;/*from www. j a va 2 s . c  om*/
                    } else {
                        Field extraField = createDefaultIndexField(PREF_LABEL);
                        extraField.setStringValue(prefLabel.getValue(locale));
                        doc.add(extraField);
                    }
                }
            }
        }
    } else if (indexFieldName.equals(ALT_LABEL)) {
        boolean first = true;
        for (SkosConceptAltLabel altLabel : skosConcept.getAltLabels()) {
            Locale locale = altLabel.getLocale();
            if (supportedLocales.contains(locale)) {
                for (String altLabelValue : skosConcept.getAltLabels(locale)) {
                    if (first) {
                        indexField.setStringValue(altLabelValue);
                        first = false;
                    } else {
                        Field extraField = createDefaultIndexField(ALT_LABEL);
                        extraField.setStringValue(altLabelValue);
                        doc.add(extraField);
                    }
                }
            }
        }
    } else if (indexFieldName.startsWith(PREF_LABEL)) {
        if (indexFieldName.indexOf("_") != -1) {
            String language = StringUtils.substringAfter(indexFieldName, "_");
            Locale locale = new Locale(language);
            String prefLabel = skosConcept.getPrefLabel(locale);
            if (StringUtils.isNotBlank(prefLabel)) {
                indexField.setStringValue(prefLabel);
            }
        }
    } else if (indexFieldName.startsWith(ALT_LABEL)) {
        String language = StringUtils.substringAfter(indexFieldName, "_");
        Locale locale = new Locale(language);
        String prefLabel = skosConcept.getPrefLabel(locale);
        if (StringUtils.isNotBlank(prefLabel)) {
            boolean first = true;
            for (String altLabelValue : skosConcept.getAltLabels(locale)) {
                if (first) {
                    indexField.setStringValue(altLabelValue);
                    first = false;
                } else {
                    Field extraField = createDefaultIndexField(indexFieldName);
                    extraField.setStringValue(altLabelValue);
                    doc.add(extraField);
                }
            }
        }
    }
}