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

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

Introduction

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

Prototype

public static String strip(String str, String stripChars) 

Source Link

Document

Strips any of a set of characters from the start and end of a String.

Usage

From source file:org.jahia.services.content.rules.RulesListener.java

/**
 * Sets the configuration for rules to be disabled. The string format is as follows:
 * /*from   w w w. ja v a2  s.com*/
 * <pre>
 * ["&lt;workspace&gt;".]"&lt;package-name-1&gt;"."&lt;rule-name-1&gt;",["&lt;workspace&gt;".]"&lt;package-name-2&gt;"."&lt;rule-name-2&gt;"...
 * </pre>
 * 
 * The workspace part is optional. For example the following configuration:
 * 
 * <pre>
 * "org.jahia.modules.rules"."Image update","live"."org.jahia.modules.dm.thumbnails"."Automatically generate thumbnail for the document"
 * </pre>
 * 
 * will disable rule <code>Image update</code> (from package <code>org.jahia.modules.rules</code>) in rules for all workspaces (live and
 * default) and the rule <code>Automatically generate thumbnail for the document</code> (package
 * <code>org.jahia.modules.dm.thumbnails</code>) will be disabled in rules for live workspace only.
 * 
 * @param rulesToDisable the configuration for rules to be disabled
 */
public void setDisabledRules(String rulesToDisable) {
    if (StringUtils.isBlank(rulesToDisable)) {
        this.disabledRules = null;
        return;
    }
    // get rid of first and last double quotes
    // split between rules considering possible multiple whitespaces between them
    String[] disabledRulesConfig = StringUtils.strip(rulesToDisable, "\"").split("\"\\s*\\,\\s*\"");
    if (disabledRulesConfig == null) {
        this.disabledRules = null;
        return;
    }

    Map<String, Map<String, Set<String>>> disabledRulesFromConfig = new HashMap<>();

    for (String ruleCfg : disabledRulesConfig) {
        // split configuration of a rule into tokens
        String[] cfg = StringUtils.splitByWholeSeparator(ruleCfg, "\".\"");
        // check if we've got a workspace part specified; if not use "null" as a workspace key
        String workspace = cfg.length == 3 ? cfg[0] : null;
        String pkg = cfg[workspace != null ? 1 : 0];
        String rule = cfg[workspace != null ? 2 : 1];

        Map<String, Set<String>> rulesForWorkspace = disabledRulesFromConfig.get(workspace);
        if (rulesForWorkspace == null) {
            rulesForWorkspace = new HashMap<>();
            disabledRulesFromConfig.put(workspace, rulesForWorkspace);
        }

        Set<String> rulesForPackage = rulesForWorkspace.get(pkg);
        if (rulesForPackage == null) {
            rulesForPackage = new HashSet<>();
            rulesForWorkspace.put(pkg, rulesForPackage);
        }

        rulesForPackage.add(rule);
    }
    disabledRules = disabledRulesFromConfig;
    logger.info("The following rules are configured to be disabled: {}", disabledRules);
}

From source file:org.jboss.as.test.integration.ejb.container.interceptor.security.api.SwitchIdentityTestCase.java

/**
 * Creates a deployment application for this test.
 *
 * @return//from   ww  w .  ja va  2 s .  c om
 * @throws IOException
 */
@Deployment
public static JavaArchive createDeployment() throws IOException {
    final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, EJBUtil.APPLICATION_NAME + ".jar");
    jar.addClasses(GuestDelegationLoginModule.class, EJBUtil.class, Manage.class, BridgeBean.class,
            TargetBean.class, CurrentUserCredential.class, ServerSecurityInterceptor.class,
            ClientSecurityInterceptor.class);
    jar.addAsManifestResource(SwitchIdentityTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
    jar.addAsManifestResource(new StringAsset(ClientSecurityInterceptor.class.getName()),
            "services/org.jboss.ejb.client.EJBClientInterceptor");
    jar.addAsManifestResource(ClientSecurityInterceptor.class.getPackage(), "jboss-ejb-client.xml",
            "jboss-ejb-client.xml");
    jar.addAsManifestResource(ClientSecurityInterceptor.class.getPackage(), "permissions.xml",
            "permissions.xml");
    jar.addAsManifestResource(
            Utils.getJBossDeploymentStructure("org.jboss.as.security-api", "org.jboss.as.core-security-api"),
            "jboss-deployment-structure.xml");
    final Properties props = EJBUtil
            .createEjbClientConfiguration(StringUtils.strip(TestSuiteEnvironment.getServerAddress(), "[]"));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    props.store(baos, null);
    jar.addAsResource(new ByteArrayAsset(baos.toByteArray()), "jboss-ejb-client.properties");
    return jar;
}

From source file:org.jboss.as.test.integration.ejb.container.interceptor.security.SwitchIdentityTestCase.java

/**
 * Creates a deployment application for this test.
 *
 * @return/*w  w  w. j ava2 s . com*/
 * @throws IOException
 */
@Deployment
public static JavaArchive createDeployment() throws IOException {
    final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, EJBUtil.APPLICATION_NAME + ".jar");
    jar.addClasses(GuestDelegationLoginModule.class, EJBUtil.class, Manage.class, BridgeBean.class,
            TargetBean.class, CurrentUserCredential.class, ServerSecurityInterceptor.class,
            ClientSecurityInterceptor.class);
    jar.addAsManifestResource(SwitchIdentityTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
    jar.addAsManifestResource(new StringAsset(ClientSecurityInterceptor.class.getName()),
            "services/org.jboss.ejb.client.EJBClientInterceptor");
    jar.addAsManifestResource(SwitchIdentityTestCase.class.getPackage(), "jboss-ejb-client.xml",
            "jboss-ejb-client.xml");
    jar.addAsManifestResource(
            org.jboss.as.test.integration.ejb.container.interceptor.security.api.ClientSecurityInterceptor.class
                    .getPackage(),
            "permissions.xml", "permissions.xml");
    jar.addAsManifestResource(Utils.getJBossDeploymentStructure("org.jboss.remoting3",
            "org.jboss.as.domain-management", "org.jboss.as.controller", "org.jboss.as.core-security"),
            "jboss-deployment-structure.xml");
    final Properties props = EJBUtil
            .createEjbClientConfiguration(StringUtils.strip(TestSuiteEnvironment.getServerAddress(), "[]"));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    props.store(baos, null);
    jar.addAsResource(new ByteArrayAsset(baos.toByteArray()), "jboss-ejb-client.properties");
    return jar;
}

From source file:org.jboss.as.test.integration.security.common.Utils.java

/**
 * Strips square brackets - '[' and ']' from the given string. It can be used for instance to remove the square brackets
 * around IPv6 address in a URL./*from ww  w .  jav  a 2 s.  c o m*/
 *
 * @param str string to strip
 * @return str without square brackets in it
 */
public static String stripSquareBrackets(final String str) {
    return StringUtils.strip(str, "[]");
}

From source file:org.jboss.as.test.integration.security.loginmodules.negotiation.PropagateIdentityServlet.java

/**
 * Retrieves a {@link GSSCredential} from {@link DelegationCredentialContext#getDelegCredential()}. If it's null error 401
 * (SC_UNAUTHORIZED) is returned, otherwise {@link GSSTestClient} is used retrieve name of propagated identity from
 * {@link GSSTestServer}.//from w  ww  . ja va2 s. co  m
 *
 * @param req
 * @param resp
 * @throws ServletException
 * @throws IOException
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    LOGGER.debug("New request coming.");
    final GSSCredential credential = DelegationCredentialContext.getDelegCredential();
    if (credential == null) {
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "GSSCredential not found");
    } else {
        resp.setContentType("text/plain");
        final PrintWriter writer = resp.getWriter();
        final GSSTestClient client = new GSSTestClient(StringUtils.strip(req.getServerName(), "[]"),
                GSSTestConstants.PORT, GSSTestConstants.PRINCIPAL);
        LOGGER.trace("Client for identity propagation created: " + client);
        try {
            writer.print(client.getName(credential));
        } catch (GSSException e) {
            if (StringUtils.startsWith(SystemUtils.JAVA_VENDOR, "IBM")
                    && e.getMessage().contains("message: Incorrect net address")) {
                writer.print("jduke@JBOSS.ORG");
            } else {
                throw new ServletException("Propagation failed.", e);
            }
        }
    }

}

From source file:org.kuali.kpme.core.ListConverter.java

@Override
public Object sqlToJava(Object arg0) throws ConversionException {

    String selectedValues = arg0.toString();
    List<String> aList = new ArrayList<String>();

    selectedValues = StringUtils.removeStart(selectedValues, "[");
    selectedValues = StringUtils.removeEnd(selectedValues, "]");
    String[] values = StringUtils.split(selectedValues, ",");

    for (String value : values) {
        aList.add(StringUtils.strip(value, " ")); // strip whitespace from the start and end
    }//from   ww  w.jav a 2 s  .co m

    return aList;
}

From source file:org.kuali.student.cm.course.service.impl.CourseMaintainableImpl.java

protected void populateOutComesOnWrapper() {

    CourseInfoWrapper courseInfoWrapper = (CourseInfoWrapper) getDataObject();
    courseInfoWrapper.getCreditOptionWrappers().clear();

    for (ResultValuesGroupInfo rvg : courseInfoWrapper.getCourseInfo().getCreditOptions()) {

        ResultValuesGroupInfoWrapper rvgWrapper = new ResultValuesGroupInfoWrapper();
        BeanUtils.copyProperties(rvg, rvgWrapper);
        rvgWrapper.setResultValuesGroupInfo(rvg);

        if (StringUtils.equals(rvg.getTypeKey(), LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE)) {

            StringBuilder resultValue = new StringBuilder("");
            List<String> resultValueList = new ArrayList<String>();

            for (String rvKey : rvg.getResultValueKeys()) {
                String value = StringUtils.strip(rvKey,
                        LrcServiceConstants.RESULT_VALUE_KEY_CREDIT_DEGREE_PREFIX);
                resultValueList.add(StringUtils.remove(value, ".0")); // This can be only be integer at ui.
            }//from w  w w.j  av  a  2 s.  co m

            // Sort the values to be displayed at ui
            Collections.sort(resultValueList);
            rvgWrapper.getUiHelper().setResultValue(StringUtils.join(resultValueList, ","));

        } else if (StringUtils.equals(rvg.getTypeKey(),
                LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE)) {

            String minValue = StringUtils.remove(rvg.getResultValueRange().getMinValue(), ".0"); // This can be only be integer at ui.
            String maxValue = StringUtils.remove(rvg.getResultValueRange().getMaxValue(), ".0"); // This can be only be integer at ui.

            rvgWrapper.getUiHelper().setResultValue(minValue + "-" + maxValue);
        } else if (StringUtils.equals(rvg.getTypeKey(),
                LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED)) {
            rvgWrapper.getUiHelper()
                    .setResultValue(StringUtils.remove(rvg.getResultValueRange().getMinValue(), ".0"));
        }
        courseInfoWrapper.getCreditOptionWrappers().add(rvgWrapper);
    }

    Collections.sort(courseInfoWrapper.getCreditOptionWrappers(),
            new Comparator<ResultValuesGroupInfoWrapper>() {
                public int compare(ResultValuesGroupInfoWrapper a, ResultValuesGroupInfoWrapper b) {
                    if (a.getTypeKey() == null) {
                        return 1;
                    } else if (b.getTypeKey() == null) {
                        return -1;
                    }
                    return a.getTypeKey().compareToIgnoreCase(b.getTypeKey());
                }
            });

    initializeOutcome(courseInfoWrapper);

}

From source file:org.mangelp.fakeSmtpWeb.httpServer.mvc.Dispatcher.java

/**
 * Gets if the path matches any of the controller paths
 *
 * @param uri// ww  w  . ja v  a 2s . c  om
 * @return
 */
private boolean isMvcPath(String uri) {
    uri = "/" + StringUtils.strip(uri, "/");

    for (String allowedPath : Dispatcher.mvcPaths) {
        if (StringUtils.equalsIgnoreCase(allowedPath, uri) || uri.matches(allowedPath)) {
            return true;
        }
    }

    return false;
}

From source file:org.mangelp.fakeSmtpWeb.httpServer.mvc.Dispatcher.java

/**
 * @param session//from   ww  w  .j  a v  a  2  s .c  o m
 * @return
 * @throws ActionHandlerException
 *             If no action handler is found for the detected action
 */
private ActionResult dispathAction(HttpGetRequest request) throws ActionHandlerException {

    String parts[] = StringUtils.strip(request.getRequestUri(), "/").split("/");
    String actionHandlerName = "default";
    String actionName = "default";

    if (parts.length > 1) {
        actionHandlerName = parts[0];
    }

    if (parts.length >= 2) {
        actionName = parts[1];
    }

    String[] subPath = ArrayUtils.EMPTY_STRING_ARRAY;

    if (parts.length > 2) {
        subPath = (String[]) ArrayUtils.subarray(parts, 2, parts.length);
    }

    String logPrefix = String.format("Handle %s$%s:%s", actionHandlerName, actionName,
            StringUtils.join(subPath, "/"));

    Dispatcher.logger.debug(logPrefix);

    AbstractActionHandler actionHandler = this.findActionHandler(actionHandlerName);

    if (actionHandler == null) {
        throw new ActionHandlerException("No action handler found for " + actionHandlerName);
    }

    Actions action = this.findAction(actionName, actionHandler);

    if (action == null) {
        throw new ActionHandlerException("No action found within the action handler for " + actionName);
    }

    ActionResult result = null;

    try {
        ActionInput input = this.createActionInput(request, actionHandler, subPath);
        result = actionHandler.execute(action, input);
    } catch (Throwable t) {
        throw new ActionHandlerException("Failed to execute " + logPrefix, t);
    }

    return result;
}

From source file:org.mangelp.fakeSmtpWeb.httpServer.mvc.resources.Resources.java

/**
 * Converts an uri into a key//from w  w  w.  j  a  v a  2  s.  co  m
 *
 * @param uri
 * @return
 */
protected String uriToKey(String uri) {
    String key = StringUtils.strip(uri, "/");
    key = key.replace('.', '_').replace('/', '.');

    return key;
}