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

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

Introduction

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

Prototype

public static String substringBefore(String str, String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:com.abssh.util.PropertyFilter.java

/**
 * @param filterName/*from   www . j a  v  a 2 s .co  m*/
 *            ,???. eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value
 *            .
 */
@SuppressWarnings("unchecked")
public PropertyFilter(final String filterName, final Object value, boolean flag) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = propertyNameStr.split(PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    // entity property.
    if (value != null && (value.getClass().isArray() || Collection.class.isInstance(value))) {
        // IN ?
        Object[] vObjects = null;
        if (value.getClass().isArray()) {
            vObjects = (Object[]) value;
        } else if (Collection.class.isInstance(value)) {
            vObjects = ((Collection) value).toArray();
        } else {
            vObjects = value.toString().split(",");
        }
        this.propertyValue = new Object[vObjects.length];
        for (int i = 0; i < vObjects.length; i++) {
            propertyValue[i] = ReflectionUtils.convertValue(vObjects[i], propertyType);
        }
    } else {
        Object tObject = ReflectionUtils.convertValue(value, propertyType);
        if (tObject != null && matchType == MatchType.LE && propertyType.getName().equals("java.util.Date")) {
            // LED ??tObject2010-08-13 00:00:00
            // ?2010-08-13 23:59:59
            Date leDate = (Date) tObject;
            Calendar c = GregorianCalendar.getInstance();
            c.setTime(leDate);
            c.set(Calendar.HOUR_OF_DAY, 23);
            c.set(Calendar.MINUTE, 59);
            c.set(Calendar.SECOND, 59);
            tObject = c.getTime();
        } else if (tObject != null && matchType == MatchType.LEN
                && propertyType.getName().equals("java.util.Date")) {
        } else if (tObject != null && matchType == MatchType.LIKE) {
            tObject = ((String) tObject).replace("%", "\\%").replace("_", "\\_");
        }
        this.propertyValue = new Object[] { tObject };
    }
}

From source file:com.doculibre.constellio.wicket.panels.results.DefaultSearchResultPanel.java

public DefaultSearchResultPanel(String id, SolrDocument doc, final SearchResultsDataProvider dataProvider) {
    super(id);//from w  w  w  .j a v a 2  s.com

    RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
    SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils
            .getSearchInterfaceConfigServices();

    String collectionName = dataProvider.getSimpleSearch().getCollectionName();

    RecordCollection collection = collectionServices.get(collectionName);
    Record record = recordServices.get(doc);
    if (record != null) {
        SearchInterfaceConfig searchInterfaceConfig = searchInterfaceConfigServices.get();

        IndexField uniqueKeyField = collection.getUniqueKeyIndexField();
        IndexField defaultSearchField = collection.getDefaultSearchIndexField();
        IndexField urlField = collection.getUrlIndexField();
        IndexField titleField = collection.getTitleIndexField();

        if (urlField == null) {
            urlField = uniqueKeyField;
        }
        if (titleField == null) {
            titleField = urlField;
        }

        final String recordURL = record.getUrl();
        final String displayURL;

        if (record.getDisplayUrl().startsWith("/get?file=")) {
            HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();
            displayURL = ContextUrlUtils.getContextUrl(req) + record.getDisplayUrl();

        } else {
            displayURL = record.getDisplayUrl();
        }

        String title = record.getDisplayTitle();

        final String protocol = StringUtils.substringBefore(displayURL, ":");
        boolean linkEnabled = isLinkEnabled(protocol);

        // rcupration des champs highlight  partir de la cl unique
        // du document, dans le cas de Nutch c'est l'URL
        QueryResponse response = dataProvider.getQueryResponse();
        Map<String, Map<String, List<String>>> highlighting = response.getHighlighting();
        Map<String, List<String>> fieldsHighlighting = highlighting.get(recordURL);

        String titleHighlight = getTitleFromHighlight(titleField.getName(), fieldsHighlighting);
        if (titleHighlight != null) {
            title = titleHighlight;
        }

        String excerpt = null;
        String description = getDescription(record);
        String summary = getSummary(record);

        if (StringUtils.isNotBlank(description) && searchInterfaceConfig.isDescriptionAsExcerpt()) {
            excerpt = description;
        } else {
            excerpt = getExcerptFromHighlight(defaultSearchField.getName(), fieldsHighlighting);
            if (excerpt == null) {
                excerpt = description;
            }
        }

        toggleSummaryLink = new WebMarkupContainer("toggleSummaryLink");
        add(toggleSummaryLink);
        toggleSummaryLink.setVisible(StringUtils.isNotBlank(summary));
        toggleSummaryLink.add(new AttributeModifier("onclick", new LoadableDetachableModel() {
            @Override
            protected Object load() {
                return "toggleSearchResultSummary('" + summaryLabel.getMarkupId() + "')";
            }
        }));

        summaryLabel = new Label("summary", summary);
        add(summaryLabel);
        summaryLabel.setOutputMarkupId(true);
        summaryLabel.setVisible(StringUtils.isNotBlank(summary));

        ExternalLink titleLink;
        if (displayURL.startsWith("file://")) {
            HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();
            String newDisplayURL = ContextUrlUtils.getContextUrl(req) + "app/getSmbFile?"
                    + SmbServletPage.RECORD_ID + "=" + record.getId() + "&" + SmbServletPage.COLLECTION + "="
                    + collectionName;
            titleLink = new ExternalLink("titleLink", newDisplayURL);
        } else {
            titleLink = new ExternalLink("titleLink", displayURL);
        }

        final RecordModel recordModel = new RecordModel(record);
        AttributeModifier computeClickAttributeModifier = new AttributeModifier("onmousedown", true,
                new LoadableDetachableModel() {
                    @Override
                    protected Object load() {
                        Record record = recordModel.getObject();
                        SimpleSearch simpleSearch = dataProvider.getSimpleSearch();
                        WebRequest webRequest = (WebRequest) RequestCycle.get().getRequest();
                        HttpServletRequest httpRequest = webRequest.getHttpServletRequest();
                        return ComputeSearchResultClickServlet.getCallbackJavascript(httpRequest, simpleSearch,
                                record);
                    }
                });
        titleLink.add(computeClickAttributeModifier);
        titleLink.setEnabled(linkEnabled);

        boolean resultsInNewWindow;
        PageParameters params = RequestCycle.get().getPageParameters();
        if (params != null && params.getString(POPUP_LINK) != null) {
            resultsInNewWindow = params.getBoolean(POPUP_LINK);
        } else {
            resultsInNewWindow = searchInterfaceConfig.isResultsInNewWindow();
        }
        titleLink.add(new SimpleAttributeModifier("target", resultsInNewWindow ? "_blank" : "_self"));

        // Add title
        title = StringUtils.remove(title, "\n");
        title = StringUtils.remove(title, "\r");
        if (StringUtils.isEmpty(title)) {
            title = StringUtils.defaultString(displayURL);
            title = StringUtils.substringAfterLast(title, "/");
            title = StringUtils.substringBefore(title, "?");
            try {
                title = URLDecoder.decode(title, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (title.length() > 120) {
                title = title.substring(0, 120) + " ...";
            }
        }

        Label titleLabel = new Label("title", title);
        titleLink.add(titleLabel.setEscapeModelStrings(false));
        add(titleLink);

        Label excerptLabel = new Label("excerpt", excerpt);
        add(excerptLabel.setEscapeModelStrings(false));
        // add(new ExternalLink("url", url,
        // url).add(computeClickAttributeModifier).setEnabled(linkEnabled));
        if (displayURL.startsWith("file://")) {
            // Creates a Windows path for file URLs
            String urlLabel = StringUtils.substringAfter(displayURL, "file:");
            urlLabel = StringUtils.stripStart(urlLabel, "/");
            urlLabel = "\\\\" + StringUtils.replace(urlLabel, "/", "\\");
            try {
                urlLabel = URLDecoder.decode(urlLabel, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            add(new Label("url", urlLabel));
        } else {
            add(new Label("url", displayURL));
        }

        final ReloadableEntityModel<RecordCollection> collectionModel = new ReloadableEntityModel<RecordCollection>(
                collection);
        add(new ListView("searchResultFields", new LoadableDetachableModel() {
            @Override
            protected Object load() {
                RecordCollection collection = collectionModel.getObject();
                return collection.getSearchResultFields();
            }

            /**
             * Detaches from the current request. Implement this method with
             * custom behavior, such as setting the model object to null.
             */
            protected void onDetach() {
                recordModel.detach();
                collectionModel.detach();
            }
        }) {
            @Override
            protected void populateItem(ListItem item) {
                SearchResultField searchResultField = (SearchResultField) item.getModelObject();
                IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices();
                Record record = recordModel.getObject();
                IndexField indexField = searchResultField.getIndexField();
                Locale locale = getLocale();
                String indexFieldTitle = indexField.getTitle(locale);
                if (StringUtils.isBlank(indexFieldTitle)) {
                    indexFieldTitle = indexField.getName();
                }
                StringBuffer fieldValueSb = new StringBuffer();
                List<Object> fieldValues = indexFieldServices.extractFieldValues(record, indexField);
                Map<String, String> defaultLabelledValues = indexFieldServices
                        .getDefaultLabelledValues(indexField, locale);
                for (Object fieldValue : fieldValues) {
                    if (fieldValueSb.length() > 0) {
                        fieldValueSb.append("\n");
                    }
                    String fieldValueLabel = indexField.getLabelledValue("" + fieldValue, locale);
                    if (fieldValueLabel == null) {
                        fieldValueLabel = defaultLabelledValues.get("" + fieldValue);
                    }
                    if (fieldValueLabel == null) {
                        fieldValueLabel = "" + fieldValue;
                    }
                    fieldValueSb.append(fieldValueLabel);
                }

                item.add(new Label("indexField", indexFieldTitle));
                item.add(new MultiLineLabel("indexFieldValue", fieldValueSb.toString()));
                item.setVisible(fieldValueSb.length() > 0);
            }

            @SuppressWarnings("unchecked")
            @Override
            public boolean isVisible() {
                boolean visible = super.isVisible();
                if (visible) {
                    List<SearchResultField> searchResultFields = (List<SearchResultField>) getModelObject();
                    visible = !searchResultFields.isEmpty();
                }
                return visible;
            }
        });

        // md5
        ConstellioSession session = ConstellioSession.get();
        ConstellioUser user = session.getUser();
        // TODO Provide access to unauthenticated users ?
        String md5 = "";
        if (user != null) {
            IntelliGIDServiceInfo intelligidServiceInfo = ConstellioSpringUtils.getIntelliGIDServiceInfo();
            if (intelligidServiceInfo != null) {
                Collection<Object> md5Coll = doc.getFieldValues(IndexField.MD5);
                if (md5Coll != null) {
                    for (Object md5Obj : md5Coll) {
                        try {
                            String md5Str = new String(Hex.encodeHex(Base64.decodeBase64(md5Obj.toString())));
                            InputStream is = HttpClientHelper
                                    .get(intelligidServiceInfo.getIntelligidUrl() + "/connector/checksum",
                                            "md5=" + URLEncoder.encode(md5Str, "ISO-8859-1"),
                                            "username=" + URLEncoder.encode(user.getUsername(), "ISO-8859-1"),
                                            "password=" + URLEncoder.encode(Base64.encodeBase64String(
                                                    ConstellioSession.get().getPassword().getBytes())),
                                            "ISO-8859-1");
                            try {
                                Document xmlDocument = new SAXReader().read(is);
                                Element root = xmlDocument.getRootElement();
                                for (Iterator<Element> it = root.elementIterator("fichier"); it.hasNext();) {
                                    Element fichier = it.next();
                                    String url = fichier.attributeValue("url");
                                    md5 += "<a href=\"" + url + "\">" + url + "</a> ";
                                }
                            } finally {
                                IOUtils.closeQuietly(is);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
        Label md5Label = new Label("md5", md5) {
            public boolean isVisible() {
                boolean visible = super.isVisible();
                if (visible) {
                    visible = StringUtils.isNotBlank(this.getModelObjectAsString());
                }
                return visible;
            }
        };
        md5Label.setEscapeModelStrings(false);
        add(md5Label);

        add(new ElevatePanel("elevatePanel", record, dataProvider.getSimpleSearch()));
    } else {
        setVisible(false);
    }
}

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

protected Object convertNodeDataStringToObject(String valueStr) {
    if (contains(valueStr, ':')) {
        final String type = StringUtils.substringBefore(valueStr, ":");
        final String value = StringUtils.substringAfter(valueStr, ":");

        // there is no beanUtils converter for Calendar
        if (type.equalsIgnoreCase("date")) {
            return ISO8601.parse(value);
        } else if (type.equalsIgnoreCase("binary")) {
            return new ByteArrayInputStream(value.getBytes());
        } else {/* ww w .j  av a  2  s . c o  m*/
            try {
                final Class<?> typeCl;
                if (type.equals("int")) {
                    typeCl = Integer.class;
                } else {
                    typeCl = Class.forName("java.lang." + StringUtils.capitalize(type));
                }
                return ConvertUtils.convert(value, typeCl);
            } catch (ClassNotFoundException e) {
                // possibly a stray :, let's ignore it for now
                return valueStr;
            }
        }
    }
    // no type specified, we assume it's a string, no conversion
    return valueStr;
}

From source file:net.contextfw.web.application.internal.servlet.UriMappingFactory.java

private Split getVariableSplit(String path, String split, Pattern verifier) {
    if (!verifier.matcher(split).matches()) {
        throw new WebApplicationException("Variable '" + split + "' in path '" + path + "' is not valid.");
    }/* w ww .  ja  v a 2s .  c  om*/
    String def = split.substring(1, split.length() - 1);
    String name = StringUtils.substringBefore(def, ":");
    String value = StringUtils.substringAfter(def, ":");
    if (StringUtils.isBlank(value)) {
        value = "[^/]+";
    }

    return new Split(value, name);
}

From source file:com.dgq.utils.Struts2Utils.java

/**
 * ?contentTypeheaders.// www  .j av  a  2  s. 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 = getResponse();

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

    return response;
}

From source file:de.tudarmstadt.ukp.dkpro.core.corenlp.internal.CoreNlp2DKPro.java

public static void convertDependencies(JCas aJCas, Annotation document, MappingProvider mappingProvider,
        boolean internStrings) {
    for (CoreMap s : document.get(SentencesAnnotation.class)) {
        SemanticGraph graph = s.get(CollapsedDependenciesAnnotation.class);
        //SemanticGraph graph = s.get(EnhancedDependenciesAnnotation.class);

        // If there are no dependencies for this sentence, skip it. Might well mean we
        // skip all sentences because normally either there are dependencies for all or for
        // none./*from  w  w w  .  j  a  v  a  2 s . co m*/
        if (graph == null) {
            continue;
        }

        for (IndexedWord root : graph.getRoots()) {
            Dependency dep = new ROOT(aJCas);
            dep.setDependencyType("root");
            dep.setDependent(root.get(TokenKey.class));
            dep.setGovernor(root.get(TokenKey.class));
            dep.setBegin(dep.getDependent().getBegin());
            dep.setEnd(dep.getDependent().getEnd());
            dep.setFlavor(DependencyFlavor.BASIC);
            dep.addToIndexes();
        }

        for (SemanticGraphEdge edge : graph.edgeListSorted()) {
            Token dependent = edge.getDependent().get(TokenKey.class);
            Token governor = edge.getGovernor().get(TokenKey.class);

            // For the type mapping, we use getShortName() instead, because the <specific>
            // actually doesn't change the relation type
            String labelUsedForMapping = edge.getRelation().getShortName();

            // The nndepparser may produce labels in which the shortName contains a colon.
            // These represent language-specific labels of the UD, cf: 
            // http://universaldependencies.github.io/docs/ext-dep-index.html
            labelUsedForMapping = StringUtils.substringBefore(labelUsedForMapping, ":");

            // Need to use toString() here to get "<shortname>_<specific>"
            String actualLabel = edge.getRelation().toString();

            Type depRel = mappingProvider.getTagType(labelUsedForMapping);
            Dependency dep = (Dependency) aJCas.getCas().createFS(depRel);
            dep.setDependencyType(internStrings ? actualLabel.intern() : actualLabel);
            dep.setDependent(dependent);
            dep.setGovernor(governor);
            dep.setBegin(dep.getDependent().getBegin());
            dep.setEnd(dep.getDependent().getEnd());
            dep.setFlavor(edge.isExtra() ? DependencyFlavor.ENHANCED : DependencyFlavor.BASIC);
            dep.addToIndexes();
        }
    }
}

From source file:com.amalto.core.server.StorageAdminImpl.java

public Storage create(String dataModelName, String storageName, StorageType type, String dataSourceName) {
    if (MDMConfiguration.getConfiguration().get(DataSourceFactory.DB_DATASOURCES) == null) {
        throw new IllegalStateException("MDM Configuration is not configured for RDBMS storage.");
    }//  w ww. ja va  2  s  . c  o  m
    if (DispatchWrapper.isMDMInternal(storageName)) {
        return internalCreateSystemStorage(dataSourceName);
    }
    String actualStorageName = StringUtils.substringBefore(storageName, STAGING_SUFFIX);
    String actualDataModelName = StringUtils.substringBefore(dataModelName, STAGING_SUFFIX);
    try {
        switch (type) {
        case MASTER:
            return internalCreateStorage(actualDataModelName, actualStorageName, dataSourceName,
                    StorageType.MASTER);
        case STAGING:
            if (supportStaging(actualStorageName)) {
                boolean hasDataSource = ServerContext.INSTANCE.get().hasDataSource(dataSourceName,
                        actualStorageName, StorageType.STAGING);
                if (hasDataSource) {
                    return internalCreateStorage(actualDataModelName, actualStorageName, dataSourceName,
                            StorageType.STAGING);
                } else {
                    throw new IllegalArgumentException(
                            "Data source '" + dataSourceName + "' does not exist for STAGING.");
                }
            } else {
                throw new IllegalArgumentException(
                        "Storage '" + actualStorageName + "' does not support STAGING.");
            }
        case SYSTEM:
        default:
            throw new IllegalStateException("System storages are not created by this method.");
        }
    } catch (Exception e) {
        throw new RuntimeException(
                "Could not create storage '" + actualStorageName + "' with data model '" + dataModelName + "'.",
                e);
    }
}

From source file:eionet.meta.dao.domain.DataElement.java

/**
 * returns external namespace prefix./*from  w  w w.  j  ava 2 s.com*/
 *
 * @return NS prefix. null if an internal namespace
 */
public String getNameSpacePrefix() {
    return isExternalSchema() ? StringUtils.substringBefore(identifier, ":") : null;
}

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.
 * /*w w w.ja v a2  s . com*/
 * @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:eionet.cr.util.URLUtil.java

/**
 * A cross-the-stream-to-get-water replacement for {@link java.net.URL#getHost()}.
 *
 * @param uri/*from  w w w .j  a  v a  2s .c  o m*/
 * @param dflt
 * @return String
 */
public static String extractUrlHost(String uri) {

    if (URLUtil.isURL(uri)) {
        String host = "";
        URL url;
        try {
            url = new URL(StringUtils.substringBefore(uri, "#"));
            host = uri.substring(0, uri.indexOf(url.getPath()));

        } catch (Exception ex) {
            // No need to throw or log it.
        }
        return host;
    } else {
        return null;
    }
}