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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

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);
    }//from www. j a v  a2 s .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.craftercms.studio.impl.v1.repository.alfresco.AlfrescoContentRepository.java

protected RepositoryItem[] getContentChildrenCMIS(String fullPath) {
    long startTime = System.currentTimeMillis();
    Map<String, String> params = new HashMap<String, String>();
    String cleanPath = fullPath.replaceAll("//", "/"); // sometimes sent bad paths
    if (cleanPath.endsWith("/")) {
        cleanPath = cleanPath.substring(0, cleanPath.length() - 1);
    }/*ww  w .  jav  a  2  s .  co  m*/
    Session session = getCMISSession();
    CmisObject cmisObject = session.getObjectByPath(cleanPath);
    String nodeRef = null;
    RepositoryItem[] items = null;
    if (cmisObject != null) {
        ObjectType type = cmisObject.getBaseType();
        if ("cmis:folder".equals(type.getId())) {
            Folder folder = (Folder) cmisObject;
            ItemIterable<CmisObject> children = folder.getChildren();
            List<RepositoryItem> tempList = new ArrayList<RepositoryItem>();
            Iterator<CmisObject> iterator = children.iterator();
            while (iterator.hasNext()) {
                CmisObject child = iterator.next();
                boolean isWorkingCopy = false;
                boolean isFolder = "cmis:folder".equals(child.getBaseType().getId());
                RepositoryItem item = new RepositoryItem();
                item.name = child.getName();

                if (BaseTypeId.CMIS_DOCUMENT.equals(child.getBaseTypeId())) {
                    org.apache.chemistry.opencmis.client.api.Document document = (org.apache.chemistry.opencmis.client.api.Document) child;
                    item.path = document.getPaths().get(0);
                    Property<?> secundaryTypes = document.getProperty(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
                    if (secundaryTypes != null) {
                        List<String> aspects = secundaryTypes.getValue();
                        if (aspects.contains("P:cm:workingcopy")) {
                            isWorkingCopy = true;
                        }
                    }
                } else if (BaseTypeId.CMIS_FOLDER.equals(child.getBaseTypeId())) {
                    Folder childFolder = (Folder) child;
                    item.path = childFolder.getPath();
                } else {
                    item.path = fullPath;
                }
                item.path = StringUtils.removeEnd(item.path, "/" + item.name);
                item.isFolder = isFolder;
                if (!isWorkingCopy) {
                    tempList.add(item);
                }
            }
            items = new RepositoryItem[tempList.size()];
            items = tempList.toArray(items);
        }
    }
    long duration = System.currentTimeMillis() - startTime;
    logger.debug("TRACE: getContentChildrenCMIS(String fullPath); {0}\n\t\tDuration: {1}", fullPath, duration);
    return items;
}

From source file:org.cruxframework.mediamanager.core.utils.QueryBuilder.java

private String buildWhereClause() {
    String where = "";
    if (filters.size() > 0) {
        where = WHERE + SPACE;//from  ww w  . jav a2s.c om

        for (Filter filter : filters) {
            String field = filter.getField();
            boolean needsAlias = isMultivaluedProperty(field) && !isRootProperty(field);

            if (needsAlias) {
                registerPropertyForJoin(filter);
            }

            if (filter.isOpenParenthesis()) {
                where += OPEN_PARENTHESIS;
            }

            switch (filter.getOperator()) {
            case NOT_EQUALS:
                where += buildNotEqualsClause(!needsAlias, filter);
                break;
            case EQUALS:
                where += buildEqualsClause(!needsAlias, filter);
                break;
            case LIKE:
                where += buildLikeClause(!needsAlias, filter);
                break;
            case LIKE_FULL:
                where += buildFullLikeClause(!needsAlias, filter);
                break;
            case LIKE_LEFT:
                where += buildLeftLikeClause(!needsAlias, filter);
                break;
            case LIKE_RIGHT:
                where += buildRightLikeClause(!needsAlias, filter);
                break;
            case GREATER_THAN:
                where += buildBinaryOperatorClause(!needsAlias, filter);
                break;
            case GREATER_THAN_OR_EQUAL:
                where += buildBinaryOperatorClause(!needsAlias, filter);
                break;
            case LESS_THAN:
                where += buildBinaryOperatorClause(!needsAlias, filter);
                break;
            case LESS_THAN_OR_EQUAL:
                where += buildBinaryOperatorClause(!needsAlias, filter);
                break;
            case MEMBER_OF:
                where += buildMemberOfClause(!needsAlias, filter);
                break;
            case NOT_MEMBER_OF:
                where += buildNotMemberOfClause(!needsAlias, filter);
                break;
            case IN:
                where += buildInClause(!needsAlias, filter);
                break;
            case NOT_IN:
                where += buildNotInClause(!needsAlias, filter);
                break;

            default:
                throw new RuntimeException("Nenhum operador informado");
            }

            if (filter.isCloseParenthesis()) {
                where += CLOSE_PARENTHESIS;
            }

            where += filter.isDisjunctive() ? " or " : " and ";
        }
        where = StringUtils.removeEnd(where, " and ");
        where = StringUtils.removeEnd(where, " or ");
    }
    return where;
}

From source file:org.cruxframework.mediamanager.core.utils.QueryBuilder.java

private String buildInClause(boolean useClassAlias, Filter filter) {
    String where = (useClassAlias ? ALIAS + "." : "") + filter.getField() + " in (";

    for (Object value : filter.getValues()) {
        String label = generateLabel();
        registerLabelAndValue(label, value);
        where += label + ", ";
    }//  w w  w. j  a  v  a  2  s  .co m
    where = StringUtils.removeEnd(where, ", ");
    where += ")";
    return where;
}

From source file:org.cruxframework.mediamanager.core.utils.QueryBuilder.java

private String buildNotInClause(boolean useClassAlias, Filter filter) {
    String where = (useClassAlias ? ALIAS + "." : "") + filter.getField() + " not in (";

    for (Object value : filter.getValues()) {
        String label = generateLabel();
        registerLabelAndValue(label, value);
        where += label + ", ";
    }// w  w  w . java 2  s  . co  m
    where = StringUtils.removeEnd(where, ", ");
    where += ")";
    return where;
}

From source file:org.devproof.portal.core.module.common.util.PortalUtil.java

public static void addSyntaxHightlighter(Component component, String theme) {
    component.add(JavascriptPackageResource.getHeaderContribution(CommonConstants.class,
            "js/SyntaxHighlighter/shCore.js"));
    component.add(JavascriptPackageResource.getHeaderContribution(CommonConstants.class,
            "js/SyntaxHighlighter/shAutoloader.js"));
    //        component.add(CSSPackageResource.getHeaderContribution(CommonConstants.class, "css/SyntaxHighlighter/shCore.css"));
    component.add(CSSPackageResource.getHeaderContribution(CommonConstants.class,
            "css/SyntaxHighlighter/shCore" + theme + ".css"));
    //        component.add(CSSPackageResource.getHeaderContribution(CommonConstants.class, "css/SyntaxHighlighter/shTheme" + theme + ".css"));
    Map<String, Object> values = new MiniMap<String, Object>(1);
    CharSequence urlWithShCore = RequestCycle.get().urlFor(CommonConstants.REF_SYNTAXHIGHLIGHTER_JS);
    CharSequence urlWithoutShCore = StringUtils.removeEnd(urlWithShCore.toString(), "shCore.js");
    values.put("jsPath", urlWithoutShCore);
    component.add(TextTemplateHeaderContributor.forJavaScript(CommonConstants.class,
            "js/SyntaxHighlighter/SyntaxHighlighterCopy.js", new MapModel<String, Object>(values)));
}

From source file:org.devproof.portal.core.module.modulemgmt.service.ModuleServiceImpl.java

private String getLocation(Class<?> clazz) {
    URL url = clazz.getResource("");
    if (!"jar".equals(url.getProtocol())) {
        return "WAR";
    } else {/*from  w ww.j av a  2 s .  c  o  m*/
        String path = url.getPath();
        String strs[] = StringUtils.split(path, '/');
        for (String str : strs) {
            if (str.endsWith("!")) {
                return StringUtils.removeEnd(str, "!");
            }
        }
        return "unknown";
    }
}

From source file:org.devproof.portal.core.module.mount.service.MountServiceImpl.java

private String removeEndingSlash(String requestedUrl) {
    if (requestedUrl.endsWith("/")) {
        requestedUrl = StringUtils.removeEnd(requestedUrl, "/");
    }/*from   ww  w. ja  va2  s. c  o  m*/
    return requestedUrl;
}

From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAConsumerUtil.java

/**
 * Gets the service client name./* w  w  w  .j av  a2s  . c  om*/
 *
 * @param project the project
 * @return the service client name
 * @throws CoreException the core exception
 */
public static String getServiceClientName(IProject project) throws CoreException {
    if (isOldClientConfigDirStructure(project) == true) {
        return project.getName();
    } else {
        final IFolder parentFolder = project.getFolder(SOAConsumerProject.META_SRC_ClIENT_CONFIG);
        if (parentFolder != null && parentFolder.exists() && parentFolder.members().length == 1) {
            //the correct directory structure
            return parentFolder.members()[0].getName();
        } else if (project.getFile(SOAProjectConstants.PROPS_FILE_SERVICE_IMPL).isAccessible()) {
            //this is an impl project that has not consumed any services yet
            //this is a dirty fix, but we could not get the service name at this point
            final String serviceName = StringUtils.removeEnd(project.getName(),
                    SOAProjectConstants.IMPL_PROJECT_SUFFIX);
            return serviceName + SOAProjectConstants.CLIENT_PROJECT_SUFFIX;
        }
    }
    return project.getName();
}

From source file:org.eclipse.gyrex.admin.ui.internal.servlets.AdminServletTracker.java

@Override
public AdminServletHolder addingService(final ServiceReference<IAdminServlet> reference) {
    final IAdminServlet servlet = context.getService(reference);
    if (servlet == null)
        return null;
    final AdminServletHolder holder = new AdminServletHolder(servlet);
    final Object alias = reference.getProperty("http.alias");
    if (alias instanceof String) {
        String pathSpec = (String) alias;
        // convert to path spec
        if (!StringUtils.endsWith(pathSpec, "/*")) {
            pathSpec = StringUtils.removeEnd(pathSpec, "/") + "/*";
        }//from   w  w  w.ja  v a  2 s  .  c  om

        try {
            // register servlet
            contextHandler.getServletHandler().addServlet(holder);

            // create, remember & register mapping
            final ServletMapping mapping = new ServletMapping();
            mapping.setPathSpec(pathSpec);
            mapping.setServletName(holder.getName());
            holder.setServletMapping(mapping);
            contextHandler.getServletHandler().addServletMapping(mapping);
        } catch (final Exception e) {
            LOG.error("Error registering contributed servlet {} ({}). {}", reference, pathSpec,
                    ExceptionUtils.getRootCauseMessage(e), e);
        }
    }
    return holder;
}