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

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

Introduction

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

Prototype

public static String remove(String str, char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

Usage

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

private String buildRepoUrl(LocalRepoDescriptor repo) {
    HttpServletRequest request = WicketUtils.getHttpServletRequest();
    String servletContextUrl = HttpUtils.getServletContextUrl(request);
    if (!servletContextUrl.endsWith("/")) {
        servletContextUrl += "/";
    }//from ww  w .  jav  a  2  s.  c  o m
    StringBuilder sb = new StringBuilder();
    if (repo instanceof LocalCacheRepoDescriptor) {
        RemoteRepoDescriptor remoteRepoDescriptor = ((LocalCacheRepoDescriptor) repo).getRemoteRepo();
        if (remoteRepoDescriptor != null) {
            sb.append(servletContextUrl).append(remoteRepoDescriptor.getKey());
        } else {
            String fixedKey = StringUtils.remove(repo.getKey(), "-cache");
            sb.append(servletContextUrl).append(fixedKey);
        }
    } else {
        sb.append(servletContextUrl).append(repo.getKey());
    }
    return sb.toString();
}

From source file:org.atomserver.core.idgenerators.UUIDEntryIdGenerator.java

public String generateId() {
    String uuid = UUID.randomUUID().toString();
    // the limit is 32 chars, and uuid has "-" chars in it
    uuid = StringUtils.remove(uuid, "-");
    log.debug("Created new EntryId = " + uuid);
    return uuid;// w w  w .  j  av  a  2  s.c om
}

From source file:org.betaconceptframework.astroboa.engine.cache.regions.JcrQueryCacheRegion.java

public static Fqn<String> constructJcrQueryFQN(String jcrQuery, CacheRegion cacheRegion) {

    //replace all '/'  and spaces with empty string
    String jcrQueryWithoutForwardSlashes = StringUtils.remove(jcrQuery, CmsConstants.FORWARD_SLASH);

    if (cacheRegion == null) {
        cacheRegion = CmsCriteria.DEFAULT_CACHE_REGION;
    }/*from   w  w w .  j av a  2 s.  co m*/

    //Create  Cache Region FQN
    Fqn<String> cacheRegionFqn = Fqn.fromRelativeElements(JCR_QUERY_NODE_FQN, cacheRegion.getRegionName());

    //Create FQN for authentication token
    String authenticationToken = AstroboaClientContextHolder.getActiveAuthenticationToken();

    if (authenticationToken == null) {
        throw new CmsException(
                "No active authenticationToken found. Could not construct appropriate FQN for query "
                        + jcrQuery);
    }

    Fqn<String> autheticationTokenFqn = Fqn.fromRelativeElements(cacheRegionFqn, authenticationToken);

    return Fqn.fromRelativeElements(autheticationTokenFqn,
            StringUtils.deleteWhitespace(jcrQueryWithoutForwardSlashes));

}

From source file:org.betaconceptframework.astroboa.engine.jcr.renderer.ContentObjectFolderRenderer.java

public ContentObjectFolder render(Session session, Node contentObjectFolderNode, int depth,
        boolean renderContentObjectIds, String locale) throws Exception {

    ContentObjectFolder contentObjectFolder = new ContentObjectFolderImpl();

    contentObjectFolder.setId(contentObjectFolderNode.getIdentifier());
    contentObjectFolder.setType(renderType(contentObjectFolderNode));
    ((ContentObjectFolderImpl) contentObjectFolder)
            .setFullPath(getFullPath(contentObjectFolderNode, contentObjectFolder.getType()));

    final String name = contentObjectFolderNode.getName();
    if (contentObjectFolder.getType() == ContentObjectFolder.Type.CONTENT_TYPE) {
        //Extract type from node name
        String typeName = StringUtils.remove(name, CmsConstants.TYPE_FOLDER);

        contentObjectFolder.setName(typeName);

        //Search for definition for this type and get localized label
        ContentObjectTypeDefinition typeDefinition = contentDefinitionDao
                .getContentObjectTypeDefinition(typeName);

        if (typeDefinition == null) {
            logger.warn("Unable to render localized label for content object folder {} for type {}", name,
                    typeName);//w  w w. j  av a2s  .c  o m
            contentObjectFolder.setLocalizedLabelForCurrentLocale(name);
        } else {
            if (StringUtils.isBlank(locale)) {
                locale = Locale.ENGLISH.toString();
            }

            contentObjectFolder.setLocalizedLabelForCurrentLocale(
                    typeDefinition.getDisplayName().getLocalizedLabelForLocale(locale));
        }
    } else {
        String label = name;

        if ((contentObjectFolder.getType() == ContentObjectFolder.Type.DAY
                || contentObjectFolder.getType() == ContentObjectFolder.Type.HOUR
                || contentObjectFolder.getType() == ContentObjectFolder.Type.MINUTE
                || contentObjectFolder.getType() == ContentObjectFolder.Type.SECOND) && label != null
                && label.length() == 1) {
            label = "0" + label;
        }

        contentObjectFolder.setLocalizedLabelForCurrentLocale(name);
        contentObjectFolder.setName(name);
    }

    final int nextDepth = CmsUtils.getNextDepth(depth);

    if (contentObjectFolder.getType() == ContentObjectFolder.Type.CONTENT_TYPE
            || contentObjectFolder.getType() == ContentObjectFolder.Type.YEAR
            || contentObjectFolder.getType() == ContentObjectFolder.Type.MONTH
            || contentObjectFolder.getType() == ContentObjectFolder.Type.HOUR
            || contentObjectFolder.getType() == ContentObjectFolder.Type.MINUTE) {

        contentObjectFolder.setNumberOfContentObjects(0);

        if (depth != TreeDepth.ZERO.asInt()) {
            //Render children
            NodeIterator subFolders = contentObjectFolderNode.getNodes();
            while (subFolders.hasNext()) {
                Node subFolderNode = subFolders.nextNode();

                if (getFolderType(subFolderNode) != null)
                    contentObjectFolder.addSubFolder(
                            render(session, subFolderNode, nextDepth, renderContentObjectIds, locale));
            }
        }
    } else if (contentObjectFolder.getType() == ContentObjectFolder.Type.DAY
            || contentObjectFolder.getType() == ContentObjectFolder.Type.SECOND) {

        //Backwards compatibility. DAY may contain content object nodes as well thus we need to make a query in order
        //to retrieve all content object child nodes

        //Perform a query to load all nodes representing content object nodes
        String contentObjectFolderPathCriterion = ISO9075.encodePath(contentObjectFolderNode.getPath())
                .replaceFirst("/", "");

        String contentObjectNodeQuery = XPathUtils.createXPathSelect(contentObjectFolderPathCriterion, null,
                CmsBuiltInItem.StructuredContentObject, true);

        //If we do not want to render content object ids then we are only interested in their number
        int limit = renderContentObjectIds ? -1 : 0;

        CmsQueryResult contentObjectNodes = cmsQueryHandler.getNodesFromXPathQuery(session,
                contentObjectNodeQuery, 0, limit);

        contentObjectFolder.setNumberOfContentObjects(contentObjectNodes.getTotalRowCount());

        if (renderContentObjectIds) {
            //Iterate over the nodes in order to retrieve content object ids
            NodeIterator childNodes = contentObjectNodes.getNodeIterator();
            while (childNodes.hasNext()) {

                Node childNode = childNodes.nextNode();
                contentObjectFolder.addContentObjectId(cmsRepositoryEntityUtils.getCmsIdentifier(childNode));
            }
        }

        //Finally, if folder is a DAY folder and depth is > 0
        //then load its subfolders
        if (contentObjectFolder.getType() == ContentObjectFolder.Type.DAY && depth != TreeDepth.ZERO.asInt()) {

            //We need to make a query to distinguish nodes, as DAY folder node may have content object nodes (version 2.x.x)
            //or hour folder nodes (version 3.x.x). In cases where both type of nodes exists then repository has been migrated from version 
            //2.x.x to 3.x.x
            String hourFolderNodeQuery = XPathUtils.createXPathSelect(contentObjectFolderPathCriterion, null,
                    CmsBuiltInItem.GenericHourFolder, true);

            CmsQueryResult hourFolderNodes = cmsQueryHandler.getNodesFromXPathQuery(session,
                    hourFolderNodeQuery, 0, -1);

            NodeIterator subFolderNodes = hourFolderNodes.getNodeIterator();

            while (subFolderNodes.hasNext()) {
                contentObjectFolder.addSubFolder(
                        render(session, subFolderNodes.nextNode(), nextDepth, renderContentObjectIds, locale));
            }
        }

    }

    return contentObjectFolder;

}

From source file:org.betaconceptframework.astroboa.engine.jcr.renderer.ContentObjectFolderRenderer.java

private String getFullPath(Node contentObjectFolderNode, Type type) throws RepositoryException {

    if (type == null) {
        return "";
    }/*from www  .  j a  v  a 2  s.  com*/

    switch (type) {
    case CONTENT_TYPE:
    case YEAR:
        return contentObjectFolderNode.getName();
    case MONTH:
    case DAY:
    case HOUR:
    case MINUTE:
    case SECOND:
        //locate contentTypeFolder folder
        Node contentTypeFolder = contentObjectFolderNode.getParent();

        while (contentTypeFolder != null
                && !contentTypeFolder.isNodeType(CmsBuiltInItem.GenericContentTypeFolder.getJcrName())) {
            contentTypeFolder = contentTypeFolder.getParent();
        }

        if (contentTypeFolder == null) {
            return contentObjectFolderNode.getName();
        }

        String path = StringUtils.remove(contentObjectFolderNode.getPath(), contentTypeFolder.getPath());

        if (path != null && path.startsWith("/")) {
            return StringUtils.removeStart(path, "/");
        }

        return path;

    default:
        break;
    }

    if (Type.MONTH == type) {
        return getMonthName(contentObjectFolderNode) + "/" + contentObjectFolderNode.getName();
    } else if (Type.DAY == type) {
        return getDayPath(contentObjectFolderNode) + "/" + getMonthName(contentObjectFolderNode) + "/"
                + contentObjectFolderNode.getName();
    } else if (Type.HOUR == type) {
        return getHourPath(contentObjectFolderNode) + "/" + getDayPath(contentObjectFolderNode) + "/"
                + getMonthName(contentObjectFolderNode) + "/" + contentObjectFolderNode.getName();
    } else if (Type.MINUTE == type) {
        return getMinutePath(contentObjectFolderNode) + "/" + getHourPath(contentObjectFolderNode) + "/"
                + getDayPath(contentObjectFolderNode) + "/" + getMonthName(contentObjectFolderNode) + "/"
                + contentObjectFolderNode.getName();
    } else if (Type.SECOND == type) {
        return contentObjectFolderNode.getParent().getParent().getParent().getParent().getParent().getName()
                + "/" + getMinutePath(contentObjectFolderNode) + "/" + getHourPath(contentObjectFolderNode)
                + "/" + getDayPath(contentObjectFolderNode) + "/" + getMonthName(contentObjectFolderNode) + "/"
                + contentObjectFolderNode.getName();
    }

    // Type.YEAR == type || Type.CONTENT_TYPE == type
    return contentObjectFolderNode.getName();
}

From source file:org.betaconceptframework.astroboa.serializer.ModelSerializer.java

private void serializeModel() {

    ResourceRepresentationType<String> output = outputIsJSON() ? ResourceRepresentationType.JSON
            : ResourceRepresentationType.XML;
    boolean prettyPrintEnabled = prettyPrintEnabled();

    boolean firstType = true;

    startElement(CmsConstants.ARRAY_OF_OBJECT_TYPE_ELEMENT_NAME, false, true);

    if (outputIsJSON()) {
        startArray(CmsConstants.OBJECT_TYPE_ELEMENT_NAME);
    }//from  w  w  w .  ja  v a2s .c o m

    List<String> contentTypes = definitionService.getContentObjectTypes();

    for (String contentType : contentTypes) {

        String contentTypeAsXmlorJson = definitionService.getCmsDefinition(contentType, output,
                prettyPrintEnabled);

        if (!outputIsJSON()) {
            //Remove XML headers
            contentTypeAsXmlorJson = StringUtils.remove(contentTypeAsXmlorJson,
                    "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
        } else {
            //Remove root element
            //contentTypeAsXmlorJson = contentTypeAsXmlorJson.replaceFirst("\\{","").replaceFirst("(.*?):", "");
            //Remove end
            //contentTypeAsXmlorJson = StringUtils.removeEnd(contentTypeAsXmlorJson, "}");

            if (!firstType) {
                contentTypeAsXmlorJson = "," + contentTypeAsXmlorJson;
            } else {
                firstType = false;
            }
        }

        writeContent(contentTypeAsXmlorJson, false);

    }

    if (outputIsJSON()) {
        endArray(CmsConstants.OBJECT_TYPE_ELEMENT_NAME);
    }

    endElement(CmsConstants.ARRAY_OF_OBJECT_TYPE_ELEMENT_NAME, false, true);

}

From source file:org.betaconceptframework.astroboa.test.engine.service.TopicServiceTest.java

@Test
public void testTopicUpdateAllowReferrerContentObjects() {

    String topicName = "test-topic-update-allowsReferrerContentObjects";

    boolean allowsReferrerContentObjects = true;

    Topic topic = JAXBTestUtils.createTopic(topicName,
            CmsRepositoryEntityFactoryForActiveClient.INSTANCE.getFactory().newTopic(), getSystemUser());

    topic.getLocalizedLabels().clear();/*from w ww  .ja v a 2  s. co  m*/

    topic.setAllowsReferrerContentObjects(true);

    topic = topicService.save(topic);
    markTopicForRemoval(topic);

    //Save using XML and JSON
    String xml = topic.xml(false);
    xml = StringUtils.remove(xml, "allowsReferrerContentObjects=\"" + allowsReferrerContentObjects + "\"");
    topic = topicService.save(xml);
    Assert.assertEquals(topic.isAllowsReferrerContentObjects(), allowsReferrerContentObjects,
            "Invalid topic allowsReferrerContentObjects");

    String json = topic.json(false);
    json = StringUtils.remove(json,
            "\"allowsReferrerContentObjects\":\"" + allowsReferrerContentObjects + "\",");
    topic = topicService.save(json);
    Assert.assertEquals(topic.isAllowsReferrerContentObjects(), allowsReferrerContentObjects,
            "Invalid topic allowsReferrerContentObjects");

}

From source file:org.bizbundles.forward.ExcelToResourceBundle.java

/**
 * private method to copy the in memory map into a resource bundle using a Properties class
 * @param generated pointer to generated File object
 * @param sheetName the name of the sheet to name the resource bundle with.
 * @param props the map of all properties
 * @throws IOException any io operations issues while creating resource bundle
 *//*  w w  w .j  a  va  2s .com*/
private void storeMapAsResourceBundle(File generated, String sheetName, Map<String, String> props)
        throws IOException {
    Set<String> set = new TreeSet<String>(props.keySet());
    listOfKeys.add(set);
    Properties properties = new Properties();
    properties.putAll(props);
    if (sheetName.endsWith(PROPERTIES_EXTENSION)) {
        sheetName = StringUtils.remove(sheetName, PROPERTIES_EXTENSION);
    }
    properties.store(
            new FileOutputStream(
                    generated.getAbsolutePath() + File.separator + sheetName + PROPERTIES_EXTENSION),
            "Generated By org.bizbundles.ExcelToResourceBundle");
    metaInfo.add(sheetName, props.keySet());
}

From source file:org.bizbundles.forward.ExcelToResourceBundle.java

private String getCellContent(Cell currCell) {
    String cellText;//  ww  w.  j  a  v a  2s .  c  o m
    if (null != currCell && CellType.DATE.equals(currCell.getType())) {
        String formatPattern = currCell.getCellFormat().getPattern().getDescription();
        if (DATE_FORMAT_LIST.contains(formatPattern)) {
            TimeZone gmtZone = TimeZone.getTimeZone("GMT");
            SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
            format.setTimeZone(gmtZone);
            DateCell dateCell = (DateCell) currCell;
            cellText = format.format(dateCell.getDate());
        } else {
            cellText = currCell.getContents();
            cellText = cellText.replace('"', ' ');
        }
    } else if (null != currCell && CellType.NUMBER.equals(currCell.getType())) {
        if ((currCell.getCellFormat().getFormat().getFormatString()).startsWith("[<=9999999]")) {
            String val = StringUtils.remove(currCell.getContents(), "[<=9999999]");
            val = StringUtils.remove(val, '-');
            cellText = val;
        } else {
            cellText = currCell.getContents();
            cellText = cellText.replace('"', ' ');
        }
    } else {
        cellText = currCell != null ? currCell.getContents() : "";
        cellText = cellText.replace('"', ' ');
    }
    //logger.info(cellText);
    return cellText.trim();
}

From source file:org.broadleafcommerce.core.web.api.BroadleafRestExceptionMapper.java

protected String resolveClientMessageKey(String key) {
    if (messageKeyPrefix != null) {
        return StringUtils.remove(key, messageKeyPrefix);
    }/* w ww  .  jav  a2  s  . co  m*/
    return key;
}