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

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

Introduction

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

Prototype

public static boolean endsWith(String str, String suffix) 

Source Link

Document

Check if a String ends with a specified suffix.

Usage

From source file:org.artifactory.webapp.wicket.page.browse.treebrowser.tabs.general.panels.GeneralInfoPanel.java

public GeneralInfoPanel init(RepoAwareActionableItem repoItem) {
    final boolean itemIsRepo = repoItem instanceof LocalRepoActionableItem;
    LocalRepoDescriptor repoDescriptor = repoItem.getRepo();
    final boolean isCache = repoDescriptor.isCache();
    RemoteRepoDescriptor remoteRepo = null;
    if (isCache) {
        remoteRepo = ((LocalCacheRepoDescriptor) repoDescriptor).getRemoteRepo();
    }/* www. ja  v  a2  s  .c  om*/

    FieldSetBorder infoBorder = new FieldSetBorder("infoBorder");
    add(infoBorder);

    LabeledValue nameLabel = new LabeledValue("name", "Name: ");
    infoBorder.add(nameLabel);

    String itemDisplayName = repoItem.getDisplayName();

    String pathUrl = BrowseRepoPage.getWicketDependableRepoPathUrl(repoItem);
    if (StringUtils.isBlank(pathUrl)) {
        pathUrl = "";
    }
    ExternalLink treeUrl = new ExternalLink("nameLink", pathUrl, itemDisplayName);
    infoBorder.add(treeUrl);
    infoBorder.add(new HelpBubble("nameLink.help",
            "Copy this link to navigate directly to this item in the tree browser."));

    LabeledValue descriptionLabel = new LabeledValue("description", "Description: ");
    descriptionLabel.setEscapeValue(false);
    String description = null;
    if (itemIsRepo) {
        if (isCache) {
            description = remoteRepo.getDescription();
        } else {
            description = repoDescriptor.getDescription();
        }
        if (description != null) {
            descriptionLabel.setValue(description.replace("\n", "<br/>"));
        }
    }
    descriptionLabel.setVisible(!StringUtils.isEmpty(description));
    infoBorder.add(descriptionLabel);

    ItemInfo itemInfo = repoItem.getItemInfo();

    LabeledValue deployedByLabel = new LabeledValue("deployed-by", "Deployed by: ", itemInfo.getModifiedBy()) {
        @Override
        public boolean isVisible() {
            return !itemIsRepo;
        }
    };
    infoBorder.add(deployedByLabel);

    //Add markup container in case we need to set the remote repo url
    WebMarkupContainer urlLabelContainer = new WebMarkupContainer("urlLabel");
    WebMarkupContainer urlContainer = new WebMarkupContainer("url");
    infoBorder.add(urlLabelContainer);
    infoBorder.add(urlContainer);

    if (isCache) {
        urlLabelContainer.replaceWith(new Label("urlLabel", "Remote URL: "));
        String remoteRepoUrl = remoteRepo.getUrl();
        if ((remoteRepoUrl != null) && (!StringUtils.endsWith(remoteRepoUrl, "/"))) {
            remoteRepoUrl += "/";
            if (repoItem instanceof FolderActionableItem) {
                remoteRepoUrl += ((FolderActionableItem) repoItem).getCanonicalPath().getPath();
            } else {
                remoteRepoUrl += repoItem.getRepoPath().getPath();
            }
        }
        ExternalLink externalLink = new ExternalLink("url", remoteRepoUrl, remoteRepoUrl);
        urlContainer.replaceWith(externalLink);
    }

    addOnlineStatusPanel(itemIsRepo, isCache, remoteRepo, infoBorder);

    final boolean repoIsBlackedOut = repoDescriptor.isBlackedOut();
    LabeledValue blackListedLabel = new LabeledValue("blackListed", "This repository is black-listed!") {
        @Override
        public boolean isVisible() {
            return repoIsBlackedOut;
        }
    };
    infoBorder.add(blackListedLabel);

    addArtifactCount(repoItem, infoBorder);

    addWatcherInfo(repoItem, infoBorder);

    final RepoPath path;
    if (repoItem instanceof FolderActionableItem) {
        path = ((FolderActionableItem) repoItem).getCanonicalPath();
    } else {
        path = repoItem.getRepoPath();
    }
    LabeledValue repoPath = new LabeledValue("repoPath", "Repository Path: ");
    infoBorder.add(repoPath);

    String pathLink = RequestUtils.getWicketServletContextUrl();
    if (!pathLink.endsWith("/")) {
        pathLink += "/";
    }
    pathLink += ArtifactoryRequest.SIMPLE_BROWSING_PATH + "/" + repoItem.getRepoPath().getRepoKey() + "/";
    if (repoItem instanceof CannonicalEnabledActionableFolder) {
        pathLink += ((CannonicalEnabledActionableFolder) repoItem).getCanonicalPath().getPath();
    } else {
        pathLink += PathUtils.getParent(repoItem.getRepoPath().getPath());
    }
    ExternalLink repoPathUrl = new ExternalLink("repoPathLink", pathLink, path + "");
    infoBorder.add(repoPathUrl);
    infoBorder.add(new HelpBubble("repoPathLink.help",
            "Copy this link to navigate directly to this item in the simple browser."));

    addItemInfoLabels(infoBorder, itemInfo);

    infoBorder.add(getLicenseInfo(repoItem));

    addLocalLayoutInfo(infoBorder, repoDescriptor, itemIsRepo);
    addRemoteLayoutInfo(infoBorder, remoteRepo, itemIsRepo);
    addLastReplicationInfo(infoBorder, path, isCache);

    addFilteredResourceCheckbox(infoBorder, itemInfo);

    infoBorder.add(new StatsTabPanel("statistics", itemInfo));

    addBintrayInfoPanel(infoBorder, itemInfo);

    return this;
}

From source file:org.b3log.symphony.util.Links.java

/**
 * Gets links from the specified HTML./*from   www.  j  a va  2 s . c o  m*/
 *
 * @param baseURL the specified base URL
 * @param html the specified HTML
 * @return a list of links, each of them like this:      <pre>
 * {
 *     "linkAddr": "https://hacpai.com/article/1440573175609",
 *     "linkTitle": "",
 *     "linkKeywords": "",
 *     "linkHTML": "page HTML",
 *     "linkText": "page text",
 *     "linkBaiduRefCnt": int
 * }
 * </pre>
 */
public static List<JSONObject> getLinks(final String baseURL, final String html) {
    final Document doc = Jsoup.parse(html, baseURL);
    final Elements urlElements = doc.select("a");

    final Set<String> urls = new HashSet<>();
    final List<Spider> spiders = new ArrayList<>();

    String url = null;
    for (final Element urlEle : urlElements) {
        try {
            url = urlEle.absUrl("href");
            if (StringUtils.isBlank(url) || !StringUtils.contains(url, "://")) {
                url = StringUtils.substringBeforeLast(baseURL, "/") + url;
            }

            final URL formedURL = new URL(url);
            final String protocol = formedURL.getProtocol();
            final String host = formedURL.getHost();
            final int port = formedURL.getPort();
            final String path = formedURL.getPath();

            url = protocol + "://" + host;
            if (-1 != port && 80 != port && 443 != port) {
                url += ":" + port;
            }
            url += path;

            if (StringUtils.endsWith(url, "/")) {
                url = StringUtils.substringBeforeLast(url, "/");
            }

            urls.add(url);
        } catch (final Exception e) {
            LOGGER.warn("Can't parse [" + url + "]");
        }
    }

    final List<JSONObject> ret = new ArrayList<>();

    try {
        for (final String u : urls) {
            spiders.add(new Spider(u));
        }

        final List<Future<JSONObject>> results = Symphonys.EXECUTOR_SERVICE.invokeAll(spiders);
        for (final Future<JSONObject> result : results) {
            final JSONObject link = result.get();
            if (null == link) {
                continue;
            }

            ret.add(link);
        }
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, "Parses URLs failed", e);
    }

    Collections.sort(ret, new Comparator<JSONObject>() {
        @Override
        public int compare(final JSONObject link1, final JSONObject link2) {
            return link1.optInt(Link.LINK_BAIDU_REF_CNT) - link2.optInt(Link.LINK_BAIDU_REF_CNT);
        }
    });

    return ret;
}

From source file:org.betaconceptframework.astroboa.resourceapi.resource.DefinitionResource.java

@GET
@Produces(MediaType.APPLICATION_XML)//from  w w  w  .  j a v a2  s.c om
@Path("/{propertyPath: " + CmsConstants.PROPERTY_PATH_REG_EXP_FOR_RESTEASY + "}")
public Response getDefinitionAsXml(@PathParam("propertyPath") String propertyPath,
        @QueryParam("output") String output, @QueryParam("callback") String callback,
        @QueryParam("prettyPrint") String prettyPrint, @Context UriInfo uriInfo) {

    boolean prettyPrintEnabled = ContentApiUtils.isPrettyPrintEnabled(prettyPrint);

    // URL-based negotiation overrides any Accept header sent by the client
    //i.e. if the url specifies the desired response type in the "output" parameter this method
    // will return the media type specified in "output" request parameter.
    Output outputEnum = Output.XML;
    if (StringUtils.isNotBlank(output)) {
        outputEnum = Output.valueOf(output.toUpperCase());

        if (outputEnum != Output.XSD && asrtoboaBuiltInModelIsRequested(propertyPath)) {
            //User has requested astroboa-model or astroboa-api built in schemata
            //but at the same time, the "output" request parameter was not XSD
            //In this case an HTTP NOT FOUND error should be returned.
            throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND);
        }
    } else {
        //User did not provide value for the "output" parameter therefore 
        //the output at this point is XML. However there is one case where the
        //user may have provide the suffix ".xsd" in the URL, requesting this
        //way the output to be an XML Schema. This case can only be traced by 
        //examining the path of the request and whether it ends in ".xsd" or not
        String path = uriInfo.getPath();

        if (StringUtils.endsWith(path, ".xsd")) {
            //User has provided the suffix ".xsd". 
            //Therefore an XML Schema sholud be returned
            //We have to attach the suffix to the propertyPath variable
            //since the user may have specified a filename instead of 
            //a property path.
            outputEnum = Output.XSD;
            if (propertyPath != null) {
                propertyPath += ".xsd";
            }
        }
    }

    return getDefinitionInternal(propertyPath, outputEnum, callback, prettyPrintEnabled);
}

From source file:org.bigmouth.nvwa.spring.file.FileConfigurator.java

public static byte[] getFile(String path) {
    path = convertKey(path);//from   w  w  w  .  j  a v a2 s . co m
    for (Entry<String, byte[]> entry : CONFS.entrySet()) {
        String key = entry.getKey();
        if (StringUtils.endsWith(key, path)) {
            return entry.getValue();
        }
    }
    return null;
}

From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java

public ConfigurationStatus disableManagedServiceFactoryConfiguration(String servicePid,
        Configuration originalConfig) throws IOException {
    Dictionary<String, Object> properties = originalConfig.getProperties();
    String originalFactoryPid = (String) properties
            .get(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID);
    if (originalFactoryPid == null) {
        throw new IOException("Configuration does not belong to a managed service factory.");
    }//from  www .  j av  a2 s  . co  m
    if (StringUtils.endsWith(originalFactoryPid, ConfigurationStatus.DISABLED_EXTENSION)) {
        throw new IOException("Configuration is already disabled.");
    }

    // Copy configuration from the original configuration and change its factory PID to end with
    // "disabled"
    Dictionary<String, Object> disabledProperties = copyConfigProperties(properties, originalFactoryPid);
    String disabledServiceFactoryPid = originalFactoryPid + ConfigurationStatus.DISABLED_EXTENSION;
    disabledProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID,
            disabledServiceFactoryPid);
    Configuration disabledConfig = configurationAdmin.createFactoryConfiguration(disabledServiceFactoryPid,
            null);
    disabledConfig.update(disabledProperties);

    // remove original configuration
    originalConfig.delete();
    return new ConfigurationStatusImpl(disabledServiceFactoryPid, disabledConfig.getPid(), originalFactoryPid,
            servicePid);
}

From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java

public ConfigurationStatus enableManagedServiceFactoryConfiguration(String servicePid,
        Configuration disabledConfig) throws IOException {
    Dictionary<String, Object> properties = disabledConfig.getProperties();
    String disabledFactoryPid = (String) properties
            .get(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID);
    if (disabledFactoryPid == null) {
        throw new IOException("Configuration does not belong to a managed service factory.");
    }//from  w  ww. ja  v  a2  s  . c om
    if (!StringUtils.endsWith(disabledFactoryPid, ConfigurationStatus.DISABLED_EXTENSION)) {
        throw new IOException("Configuration is already enabled.");
    }

    String enabledFactoryPid = StringUtils.removeEnd(disabledFactoryPid,
            ConfigurationStatus.DISABLED_EXTENSION);
    Dictionary<String, Object> enabledProperties = copyConfigProperties(properties, enabledFactoryPid);
    enabledProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, enabledFactoryPid);
    Configuration enabledConfiguration = configurationAdmin.createFactoryConfiguration(enabledFactoryPid, null);
    enabledConfiguration.update(enabledProperties);

    disabledConfig.delete();

    return new ConfigurationStatusImpl(enabledFactoryPid, enabledConfiguration.getPid(), disabledFactoryPid,
            servicePid);
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdmin.java

public Map<String, Object> disableConfiguration(String servicePid) throws IOException {
    if (StringUtils.isEmpty(servicePid)) {
        throw new IOException(
                "Service PID of Source to be disabled must be specified.  Service PID provided: " + servicePid);
    }/*  w ww.  j  a v a  2s . c o  m*/

    Configuration originalConfig = configurationAdminExt.getConfiguration(servicePid);

    if (originalConfig == null) {
        throw new IOException("No Source exists with the service PID: " + servicePid);
    }

    Dictionary<String, Object> properties = originalConfig.getProperties();
    String originalFactoryPid = (String) properties
            .get(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID);
    if (StringUtils.endsWith(originalFactoryPid, DISABLED)) {
        throw new IOException("Source is already disabled.");
    }

    // Copy configuration from the original configuration and change its factory PID to end with
    // "disabled"
    String disabledServiceFactoryPid = originalFactoryPid + DISABLED;
    properties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, disabledServiceFactoryPid);
    Configuration disabledConfig = configurationAdmin.createFactoryConfiguration(disabledServiceFactoryPid,
            null);
    disabledConfig.update(properties);

    // remove original configuration
    originalConfig.delete();

    Map<String, Object> rval = new HashMap<>();
    rval.put(ORIGINAL_PID, servicePid);
    rval.put(ORIGINAL_FACTORY_PID, originalFactoryPid);
    rval.put(NEW_PID, disabledConfig.getPid());
    rval.put(NEW_FACTORY_PID, disabledServiceFactoryPid);
    return rval;
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdmin.java

public Map<String, Object> enableConfiguration(String servicePid) throws IOException {
    if (StringUtils.isEmpty(servicePid)) {
        throw new IOException(
                "Service PID of Source to be disabled must be specified.  Service PID provided: " + servicePid);
    }//  ww w .j a  va2s .  co  m

    Configuration disabledConfig = configurationAdminExt.getConfiguration(servicePid);

    if (disabledConfig == null) {
        throw new IOException("No Source exists with the service PID: " + servicePid);
    }

    Dictionary<String, Object> properties = disabledConfig.getProperties();
    String disabledFactoryPid = (String) properties
            .get(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID);
    if (!StringUtils.endsWith(disabledFactoryPid, DISABLED)) {
        throw new IOException("Source is already enabled.");
    }

    String enabledFactoryPid = StringUtils.removeEnd(disabledFactoryPid, DISABLED);
    properties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, enabledFactoryPid);
    Configuration enabledConfiguration = configurationAdmin.createFactoryConfiguration(enabledFactoryPid, null);
    enabledConfiguration.update(properties);

    disabledConfig.delete();

    Map<String, Object> rval = new HashMap<>();
    rval.put(ORIGINAL_PID, servicePid);
    rval.put(ORIGINAL_FACTORY_PID, disabledFactoryPid);
    rval.put(NEW_PID, enabledConfiguration.getPid());
    rval.put(NEW_FACTORY_PID, enabledFactoryPid);
    return rval;
}

From source file:org.codice.proxy.http.HttpProxyWrappedCleanRequest.java

@Override
public String getQueryString() {
    String queryString = super.getQueryString();
    // If query string ends with an ampersand, take it off
    if (StringUtils.endsWith(queryString, "&")) {
        queryString = StringUtils.chop(queryString);
    }/*w ww .j av  a 2  s  .c  om*/
    return queryString;
}

From source file:org.easycloud.las.agent.LogClearThread.java

private boolean shouldDelete(String rootPath, DateFormat df, Date lastPushedTime, File logDir) {
    String absDirPath = logDir.getAbsolutePath();
    String relDirPath = StringUtils.remove(absDirPath, rootPath);
    // TODO hard code "/" here, maybe the windows can't be supported
    if (StringUtils.startsWith(relDirPath, "/")) {
        relDirPath = relDirPath.substring(1);
    }//from ww w . ja v a 2s.  c  om
    if (StringUtils.endsWith(relDirPath, "/")) {
        relDirPath = relDirPath.substring(0, relDirPath.length() - 1);
    }
    Date loggingTime = parseDate(relDirPath, df);
    if (loggingTime == null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("LogPushThread: Parsing the log directory [" + logDir.getPath()
                    + "] failed, and it's skipped.");
        }
        return false;
    } else {
        return TimeUtil.isBeforeNow(loggingTime,
                agentConfiguration.getInt(LOG_CLEAR_BEFORE, DEFAULT_BEFORE_DAYS), Calendar.DATE)
                && TimeUtil.isBefore(loggingTime, lastPushedTime);
    }
}