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.brushingbits.jnap.persistence.hibernate.DynaQueryBuilder.java

public Criteria build() throws QueryException {
    Matcher matcher = DYNA_QUERY_PATTERN.matcher(this.dynaQuery);
    if (!matcher.matches()) {
        throw new QueryException("The DynaQuery syntax is incorrect. It must start with 'findBy' "
                + ", findUniqueBy or 'countBy' expression followed by property expressions and operators.",
                this.dynaQuery);
    }/*from  w w  w.  ja  va2 s .  c om*/
    Criteria criteria = this.createCriteria(matcher.group(1).equals("countBy"));
    String dynaQueryExpression = matcher.group(2);

    // order by
    Matcher orderByMatcher = ORDER_BY_PATTERN.matcher(dynaQueryExpression);
    if (orderByMatcher.find()) {
        dynaQueryExpression = StringUtils.remove(dynaQueryExpression, orderByMatcher.group());
        String orderByProperty = normalizePropertyName(orderByMatcher.group(3));
        String orderByDirection = orderByMatcher.group(4);
        Order orderBy = "Desc".equals(orderByDirection) ? Order.desc(orderByProperty)
                : Order.asc(orderByProperty);
        criteria.addOrder(orderBy);
    }

    // split properties
    String[] properties = DYNA_QUERY_OPERATOR_PATTERN.split(dynaQueryExpression);
    if (properties.length == 0 || properties.length > 2) {
        throw new QueryException(format(
                "The DynaQuery syntax is incorrect. Dynamic queries must have "
                        + "at least one property an no more than two (yours has {0}).\nYou can use one of "
                        + "the following logical operators ({1}) and these expression operators ({2})",
                properties.length, LOGICAL_OPERATOR_AND + ", " + LOGICAL_OPERATOR_OR,
                StringUtils.join(EXPRESSION_OPERATORS, ", ")), this.dynaQuery);
    }
    Matcher logicalOperatorsMatcher = DYNA_QUERY_OPERATOR_PATTERN.matcher(dynaQueryExpression);
    String logicalOperator = logicalOperatorsMatcher.find() ? logicalOperatorsMatcher.group(1)
            : LOGICAL_OPERATOR_AND;
    Junction junction = LOGICAL_OPERATOR_OR.equals(logicalOperator) ? Restrictions.disjunction()
            : Restrictions.conjunction();
    for (String property : properties) {
        junction.add(this.createCriterion(property));
    }
    criteria.add(junction);
    return criteria;
}

From source file:org.brushingbits.jnap.persistence.hibernate.DynaQueryBuilder.java

private Criterion createCriterion(final String property) {
    String propertyName = property;
    String criterionType = EQUAL;
    for (String expression : EXPRESSION_OPERATORS) {
        if (property.endsWith(expression)) {
            criterionType = expression;/*from w  w w. ja  v a 2 s  .  com*/
            propertyName = StringUtils.remove(propertyName, criterionType);
            break;
        }
    }
    propertyName = normalizePropertyName(propertyName);
    return this.criterionBuilderMap.get(criterionType).build(propertyName);
}

From source file:org.cesecore.certificates.ca.X509CA.java

/**
 * Constructs the SubjectAlternativeName extension that will end up on the generated certificate.
 * //from w  w w. j  ava  2  s .  c  om
 * If the DNS values in the subjectAlternativeName extension contain parentheses to specify labels that should be redacted, the parentheses are removed and another extension 
 * containing the number of redacted labels is added.
 * 
 * @param subAltNameExt
 * @param publishToCT
 * @return An extension generator containing the SubjectAlternativeName extension and an extension holding the number of redacted labels if the certificate is to be published 
 * to a CTLog
 * @throws IOException
 */
private ExtensionsGenerator getSubjectAltNameExtensionForCert(Extension subAltNameExt, boolean publishToCT)
        throws IOException {
    String subAltName = CertTools.getAltNameStringFromExtension(subAltNameExt);
    List<String> dnsValues = CertTools.getPartsFromDN(subAltName, CertTools.DNS);
    int[] nrOfRecactedLables = new int[dnsValues.size()];
    boolean sanEdited = false;
    int i = 0;
    for (String dns : dnsValues) {
        if (StringUtils.contains(dns, "(") && StringUtils.contains(dns, ")")) { // if it contains parts that should be redacted
            // Remove the parentheses from the SubjectAltName that will end up on the certificate
            String certBuilderDNSValue = StringUtils.remove(dns, '(');
            certBuilderDNSValue = StringUtils.remove(certBuilderDNSValue, ')');
            subAltName = StringUtils.replace(subAltName, dns, certBuilderDNSValue);
            sanEdited = true;
            if (publishToCT) {
                String redactedLable = StringUtils.substring(dns, StringUtils.indexOf(dns, "("),
                        StringUtils.lastIndexOf(dns, ")") + 1); // tex. (top.secret).domain.se => redactedLable = (top.secret) aka. including the parentheses 
                nrOfRecactedLables[i] = StringUtils.countMatches(redactedLable, ".") + 1;
            }
        }
        i++;
    }
    ExtensionsGenerator gen = new ExtensionsGenerator();
    gen.addExtension(Extension.subjectAlternativeName, subAltNameExt.isCritical(),
            CertTools.getGeneralNamesFromAltName(subAltName));
    // If there actually are redacted parts, add the extension containing the number of redacted lables to the certificate 
    if (publishToCT && sanEdited) {
        ASN1EncodableVector v = new ASN1EncodableVector();
        for (int val : nrOfRecactedLables) {
            v.add(new ASN1Integer(val));
        }
        ASN1Encodable seq = new DERSequence(v);
        gen.addExtension(new ASN1ObjectIdentifier("1.3.6.1.4.1.11129.2.4.6"), false, seq);
    }

    return gen;
}

From source file:org.cesecore.dbprotection.ProtectedDataConfiguration.java

/**
  * Fill the maps with crypto tokens and key labels from the configuration file
  *//* www. ja v a  2s  .  co  m*/
private void fillKeyIdsAndCryptoTokens() {
    final Configuration conf = ConfigurationHolder.instance();
    final String keyidstr = "databaseprotection.keyid.";
    final String labelstr = "databaseprotection.keylabel.";
    final String classtr = "databaseprotection.classname.";
    final String propstr = "databaseprotection.properties.";
    final String datastr = "databaseprotection.data.";
    final String pinstr = "databaseprotection.tokenpin.";
    final String versionstr = "databaseprotection.version.";
    for (int i = 0; i < 255; i++) {
        final String keyid = conf.getString(keyidstr + i);
        if (keyid != null) {
            // Get label, must exist
            String label = conf.getString(labelstr + i);
            if (label != null) {
                // A null value in the properties file means that we should not use this value, so set it to null for real
                if (label.equalsIgnoreCase("null")) {
                    label = null;
                    log.info("Found keyid " + keyid
                            + ", but label defined as 'null'. Not adding to list of crypto tokens.");
                } else {
                    // Get version string, there is a default
                    final String version = conf.getString(versionstr + i);
                    if (StringUtils.isNotEmpty(version)) {
                        protectVersions.put(Integer.parseInt(keyid), Integer.parseInt(version));
                    }
                    // Get classname, must exist
                    final String classname = conf.getString(classtr + i);
                    if (StringUtils.isNotEmpty(classname)) {
                        // Get properties and data not required
                        // Properties (string with comma in it) are returned as an ArrayList so we can not use: final String str = conf.getString(propstr+i);
                        Object o = conf.getProperty(propstr + i);
                        String str = "";
                        if (o instanceof String) {
                            str = (String) o;
                        } else if (o != null) {
                            @SuppressWarnings("unchecked")
                            final ArrayList<String> list = (ArrayList<String>) o;
                            // We have to do a bit of magic in order to make the properties into something that 
                            // Properties.load will swallow, it is a bit stupid.
                            for (String s : list) {
                                if (str.length() > 0) {
                                    str += "\n";
                                }
                                str += s;
                            }
                        }
                        final Properties properties = new Properties();
                        try {
                            if (StringUtils.isNotEmpty(str)) {
                                // Remove any curly braces from the input, otherwise Properties.load does not do what we want
                                str = StringUtils.remove(str, '{');
                                str = StringUtils.remove(str, '}');
                                // If the input string contains \ (backslash on windows) we must convert it to \\
                                // Otherwise properties.load will parse it as an escaped character, and that is not good
                                str = StringUtils.replace(str, "\\", "\\\\");
                                properties.load(new ByteArrayInputStream(str.getBytes()));
                            }
                            final String data = conf.getString(datastr + i);
                            byte[] keydata = null;
                            if (StringUtils.isNotEmpty(data)) {
                                // Data is base64 encoded byte[] so decode it
                                keydata = Base64.decode(data.getBytes());
                            }
                            final CryptoToken token = CryptoTokenFactory.createCryptoToken(classname,
                                    properties, keydata, Integer.valueOf(keyid).intValue());
                            // We must activate the token as well (if not using a default pwd of course, in which case we assume the tokenpin property is not set)
                            final String pin = conf.getString(pinstr + i);
                            try {
                                if (StringUtils.isNotEmpty(pin)) {
                                    token.activate(pin.toCharArray());
                                }
                                cryptoTokens.put(Integer.parseInt(keyid), new CachedCryptoToken(token));
                                keyLabels.put(Integer.parseInt(keyid), label);
                            } catch (CryptoTokenAuthenticationFailedException e) {
                                log.error("Found keyid " + keyid
                                        + ", but activation of crypto token fails. Not adding to list of crypto tokens.",
                                        e);
                            } catch (CryptoTokenOfflineException e) {
                                log.error("Found keyid " + keyid
                                        + ", but activation of crypto token fails. Not adding to list of crypto tokens.",
                                        e);
                            }
                        } catch (IOException e) {
                            log.error("Found keyid " + keyid
                                    + ", but properties fails to load. Not adding to list of crypto tokens.",
                                    e);
                        }
                    } else {
                        log.error("Found keyid " + keyid
                                + ", but no classname defined. Not adding to list of crypto tokens.");
                    }
                }
            } else {
                log.error("Found keyid " + keyid
                        + ", but no label defined. Not adding to list of crypto tokens.");
            }
        } else {
            // No keyid with that number = no more keyids so break,
            log.debug("Read " + i + " crypto tokens for protected data.");
            break;
        }

        // After reading this, get the default key label
        final String defaultstr = "databaseprotection.keyid";
        final String defkeyid = conf.getString(defaultstr);
        if (StringUtils.isEmpty(defkeyid)) {
            log.error("No default key id, will not be able to use database protection.");
        }
        defaultkeyId = Integer.valueOf(defkeyid);

    }
}

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

private String getEndpointNameFromPath(String path) {
    // path is like: "/example1/something/0/thing.html"
    // or is like: "/example1"
    // endpointName is: "example1"
    String endpointName = (StringUtils.indexOf(path, "/", 1) != StringUtils.INDEX_NOT_FOUND)
            ? StringUtils.substring(path, 0, StringUtils.indexOf(path, "/", 1))
            : path;//  ww  w .ja v  a 2 s . c o m
    endpointName = StringUtils.remove(endpointName, "/");
    return endpointName;
}

From source file:org.devproof.portal.module.article.mount.ArticleMountHandler.java

@Override
@Transactional(readOnly = true)/*  w ww.  j  a  v  a  2 s . com*/
public IRequestTarget getRequestTarget(String requestedUrl, MountPoint mountPoint) {
    String relatedContentId = mountPoint.getRelatedContentId();
    PageParameters pageParameters = new PageParameters("0=" + relatedContentId);
    String rest = StringUtils.substringAfter(requestedUrl, mountPoint.getMountPath());
    if (StringUtils.isNotBlank(rest)) {
        String page = StringUtils.remove(rest, '/');
        if ("print".equals(page)) {
            return new BookmarkablePageRequestTarget(ArticlePrintPage.class, pageParameters);
        } else if (StringUtils.isNumeric(page)) {
            pageParameters.put("1", page);
        }
    }
    return new BookmarkablePageRequestTarget(ArticleReadPage.class, pageParameters);
}

From source file:org.devproof.portal.module.blog.mount.BlogMountHandler.java

@Override
@Transactional(readOnly = true)/*  ww w  .ja  va2 s .  c o  m*/
public IRequestTarget getRequestTarget(String requestedUrl, MountPoint mountPoint) {
    String relatedContentId = mountPoint.getRelatedContentId();
    PageParameters pageParameters = new PageParameters("id=" + relatedContentId);
    String rest = StringUtils.substringAfter(requestedUrl, mountPoint.getMountPath());
    if (StringUtils.isNotBlank(rest)) {
        String page = StringUtils.remove(rest, '/');
        if ("print".equals(page)) {
            return new BookmarkablePageRequestTarget(BlogPrintPage.class, pageParameters);
        }
    }
    return new BookmarkablePageRequestTarget(BlogPage.class, pageParameters);
}

From source file:org.devproof.portal.module.bookmark.mount.BookmarkMountHandler.java

@Override
@Transactional(readOnly = true)/* www  .  j av a 2s  .co  m*/
public IRequestTarget getRequestTarget(String requestedUrl, MountPoint mountPoint) {
    String relatedContentId = mountPoint.getRelatedContentId();
    String rest = StringUtils.substringAfter(requestedUrl, mountPoint.getMountPath());
    if (StringUtils.isNotBlank(rest)) {
        String page = StringUtils.remove(rest, '/');
        if ("visit".equals(page)) {
            PageParameters pageParameters = new PageParameters("0=" + relatedContentId);
            return new BookmarkablePageRequestTarget(BookmarkRedirectPage.class, pageParameters);
        }
    }
    PageParameters pageParameters = new PageParameters("id=" + relatedContentId);
    return new BookmarkablePageRequestTarget(BookmarkPage.class, pageParameters);
}

From source file:org.devproof.portal.module.download.mount.DownloadMountHandler.java

@Override
@Transactional(readOnly = true)// ww  w.  j a  v  a 2  s .c  om
public IRequestTarget getRequestTarget(String requestedUrl, MountPoint mountPoint) {
    String relatedContentId = mountPoint.getRelatedContentId();
    String rest = StringUtils.substringAfter(requestedUrl, mountPoint.getMountPath());
    if (StringUtils.isNotBlank(rest)) {
        String page = StringUtils.remove(rest, '/');
        if ("download".equals(page)) {
            PageParameters pageParameters = new PageParameters("0=" + relatedContentId);
            return new BookmarkablePageRequestTarget(DownloadRedirectPage.class, pageParameters);
        }
    }
    PageParameters pageParameters = new PageParameters("id=" + relatedContentId);
    return new BookmarkablePageRequestTarget(DownloadPage.class, pageParameters);
}

From source file:org.drugis.addis.gui.builder.StudyOutcomeMeasuresView.java

private JButton createRatioButton(final RelativeEffectTableModel tableModel) {
    JButton button = new JButton(StringUtils.remove(tableModel.getTitle(), " Table"));
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            RelativeEffectTableDialog dlg = new RelativeEffectTableDialog(d_mainWindow, tableModel);
            dlg.setVisible(true);//from w w w  . j a v a  2s.c  o  m
        }
    });
    return button;
}