Example usage for org.apache.commons.lang3 StringUtils substringAfter

List of usage examples for org.apache.commons.lang3 StringUtils substringAfter

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfter.

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:org.apache.olingo.client.core.serialization.ContextURLParser.java

public static ContextURL parse(final URI contextURL) {
    if (contextURL == null) {
        return null;
    }/* w ww. j  a  v a 2  s.com*/

    final ContextURL.Builder contextUrl = ContextURL.with();

    String contextURLasString = contextURL.toASCIIString();

    boolean isEntity = false;
    if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) {
        isEntity = true;
        contextUrl.suffix(Suffix.ENTITY);
        contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY).replace("/@Element",
                StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$ref")) {
        contextUrl.suffix(Suffix.REFERENCE);
        contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$delta")) {
        contextUrl.suffix(Suffix.DELTA);
        contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$deletedEntity")) {
        contextUrl.suffix(Suffix.DELTA_DELETED_ENTITY);
        contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$link")) {
        contextUrl.suffix(Suffix.DELTA_LINK);
        contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$deletedLink")) {
        contextUrl.suffix(Suffix.DELTA_DELETED_LINK);
        contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY);
    }

    contextUrl.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA)));

    final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#");

    String firstToken;
    String entitySetOrSingletonOrType;
    if (rest.startsWith("Collection(")) {
        firstToken = rest.substring(0, rest.indexOf(')') + 1);
        entitySetOrSingletonOrType = firstToken;
    } else {
        final int openParIdx = rest.indexOf('(');
        if (openParIdx == -1) {
            firstToken = StringUtils.substringBeforeLast(rest, "/");

            entitySetOrSingletonOrType = firstToken;
        } else {
            firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")";

            final List<String> parts = new ArrayList<String>();
            for (String split : firstToken.split("\\)/")) {
                parts.add(split.replaceAll("\\(.*", ""));
            }
            entitySetOrSingletonOrType = StringUtils.join(parts, '/');
            final int commaIdx = firstToken.indexOf(',');
            if (commaIdx != -1) {
                contextUrl.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1));
            }
        }
    }
    contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType);

    final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/');
    if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) {
        contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType.substring(0, slashIdx));
        contextUrl.derivedEntity(entitySetOrSingletonOrType.substring(slashIdx + 1));
    }

    if (!firstToken.equals(rest)) {
        final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/");
        if (pathElems.length > 0 && pathElems[0].length() > 0) {
            if (pathElems[0].indexOf('.') == -1) {
                contextUrl.navOrPropertyPath(pathElems[0]);
            } else {
                contextUrl.derivedEntity(pathElems[0]);
            }

            if (pathElems.length > 1) {
                contextUrl.navOrPropertyPath(pathElems[1]);
            }
        }
    }

    return contextUrl.build();
}

From source file:org.apache.olingo.commons.core.serialization.ContextURLParser.java

public static ContextURL parse(final URI contextURL) {
    if (contextURL == null) {
        return null;
    }/* w  w w  .  ja  va2  s  .  com*/

    final ContextURL.Builder builder = ContextURL.Builder.create();

    String contextURLasString = contextURL.toASCIIString();

    boolean isEntity = false;
    if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) {
        isEntity = true;
        builder.suffix(Suffix.ENTITY);
        contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY).replace("/@Element",
                StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$ref")) {
        builder.suffix(Suffix.REFERENCE);
        contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$delta")) {
        builder.suffix(Suffix.DELTA);
        contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$deletedEntity")) {
        builder.suffix(Suffix.DELTA_DELETED_ENTITY);
        contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$link")) {
        builder.suffix(Suffix.DELTA_LINK);
        contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$deletedLink")) {
        builder.suffix(Suffix.DELTA_DELETED_LINK);
        contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY);
    }

    builder.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA)));

    final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#");

    String firstToken;
    String entitySetOrSingletonOrType = null;
    if (rest.startsWith("Collection(")) {
        firstToken = rest.substring(0, rest.indexOf(')') + 1);
        entitySetOrSingletonOrType = firstToken;
    } else {
        final int openParIdx = rest.indexOf('(');
        if (openParIdx == -1) {
            firstToken = StringUtils.substringBeforeLast(rest, "/");

            entitySetOrSingletonOrType = firstToken;
        } else {
            firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")";

            final List<String> parts = new ArrayList<String>();
            for (String split : firstToken.split("\\)/")) {
                parts.add(split.replaceAll("\\(.*", ""));
            }
            entitySetOrSingletonOrType = StringUtils.join(parts, '/');
            final int commaIdx = firstToken.indexOf(',');
            if (commaIdx != -1) {
                builder.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1));
            }
        }
    }
    builder.entitySetOrSingletonOrType(entitySetOrSingletonOrType);

    final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/');
    if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) {
        final String clone = entitySetOrSingletonOrType;
        builder.entitySetOrSingletonOrType(clone.substring(0, slashIdx));
        builder.derivedEntity(clone.substring(slashIdx + 1));
    }

    if (!firstToken.equals(rest)) {
        final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/");
        if (pathElems.length > 0 && pathElems[0].length() > 0) {
            if (pathElems[0].indexOf('.') == -1) {
                builder.navOrPropertyPath(pathElems[0]);
            } else {
                builder.derivedEntity(pathElems[0]);
            }

            if (pathElems.length > 1) {
                builder.navOrPropertyPath(pathElems[1]);
            }
        }
    }

    return builder.build();
}

From source file:org.apache.olingo.fit.rest.OAuth2RequestFilter.java

@Override
public void filter(final ContainerRequestContext context) {
    final String svcName = StringUtils
            .substringBefore(StringUtils.substringAfter(context.getUriInfo().getPath(), "/"), "/");
    if ("OAuth2.svc".equals(svcName)) {
        super.filter(context);
    }/*from   w  w w.  ja va 2  s.co  m*/
}

From source file:org.apache.olingo.fit.rest.ServiceNameResponseFilter.java

@Override
public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext)
        throws IOException {

    final String svcName = StringUtils
            .substringBefore(StringUtils.substringAfter(requestContext.getUriInfo().getPath(), "/"), "/");

    if ("OAuth2.svc".equals(svcName) && responseContext.getEntity() != null) {
        final String content = IOUtils.toString((InputStream) responseContext.getEntity(), Constants.ENCODING)
                .replaceAll("Static\\.svc", svcName);

        final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy(toBeStreamedBack, baos);
        IOUtils.closeQuietly(toBeStreamedBack);

        responseContext.setEntity(new ByteArrayInputStream(baos.toByteArray()));
    }/*from  w ww.  java2 s .  c  om*/
}

From source file:org.apache.rave.portal.web.controller.handler.OpenIDAuthenticationFailureHandler.java

private User createTemporaryUser(OpenIDAuthenticationToken token, final String openId) {
    final List<OpenIDAttribute> attributes = token.getAttributes();
    String email = null;/*w w w. j  av  a  2 s  .  c o  m*/
    String firstName = null;
    String lastName = null;
    String displayName = null;
    for (OpenIDAttribute attribute : attributes) {
        if ("email".equals(attribute.getName()) && !attribute.getValues().isEmpty()) {
            email = attribute.getValues().get(0);
        } else if ("firstname".equals(attribute.getName()) && !attribute.getValues().isEmpty()) {
            firstName = attribute.getValues().get(0);
        } else if ("lastname".equals(attribute.getName()) && !attribute.getValues().isEmpty()) {
            lastName = attribute.getValues().get(0);
        } else if ("fullname".equals(attribute.getName()) && !attribute.getValues().isEmpty()) {
            displayName = attribute.getValues().get(0);
        }
    }
    User user = new UserImpl();
    String username = StringUtils.substringAfter(openId, "://").replace("/", "");
    if (username.length() > 35) {
        username = username.substring(0, 35);
    }
    if (displayName == null && firstName != null && lastName != null) {
        displayName = firstName + " " + lastName;
    }
    user.setUsername(username);
    user.setEmail(email);
    user.setGivenName(firstName);
    user.setFamilyName(lastName);
    user.setDisplayName(displayName);
    user.setOpenId(openId);

    return user;
}

From source file:org.apache.sling.servlethelpers.MockSlingHttpServletRequest.java

public void setContentType(String type) {
    this.contentType = type;
    if (StringUtils.contains(this.contentType, CHARSET_SEPARATOR)) {
        this.characterEncoding = StringUtils.substringAfter(this.contentType, CHARSET_SEPARATOR);
        this.contentType = StringUtils.substringBefore(this.contentType, CHARSET_SEPARATOR);
    }/*  w  w w.  jav  a  2  s.  co m*/
}

From source file:org.apache.sling.servlethelpers.MockSlingHttpServletResponse.java

@Override
public void setContentType(String type) {
    this.contentType = type;
    if (StringUtils.contains(this.contentType, CHARSET_SEPARATOR)) {
        this.characterEncoding = StringUtils.substringAfter(this.contentType, CHARSET_SEPARATOR);
        this.contentType = StringUtils.substringBefore(this.contentType, CHARSET_SEPARATOR);
    }/*  w  w w .  j av a2 s  . c  om*/
}

From source file:org.apache.streams.util.schema.SchemaStoreImpl.java

@Override
public synchronized Schema create(URI uri) {
    if (!getByUri(uri).isPresent()) {
        URI baseUri = UriUtil.removeFragment(uri);
        JsonNode baseNode = this.contentResolver.resolve(baseUri);
        if (uri.toString().contains("#") && !uri.toString().endsWith("#")) {
            Schema newSchema = new Schema(baseUri, baseNode, null, true);
            this.schemas.put(baseUri, newSchema);
            JsonNode childContent = this.fragmentResolver.resolve(baseNode,
                    '#' + StringUtils.substringAfter(uri.toString(), "#"));
            this.schemas.put(uri, new Schema(uri, childContent, newSchema, false));
        } else {//  ww w  .ja  v a  2s.co m
            if (baseNode.has("extends") && baseNode.get("extends").isObject()) {
                URI ref = URI.create((baseNode.get("extends")).get("$ref").asText());
                URI absoluteUri;
                if (ref.isAbsolute()) {
                    absoluteUri = ref;
                } else {
                    absoluteUri = baseUri.resolve(ref);
                }
                JsonNode parentNode = this.contentResolver.resolve(absoluteUri);
                Schema parentSchema;
                if (this.schemas.get(absoluteUri) != null) {
                    parentSchema = this.schemas.get(absoluteUri);
                } else {
                    parentSchema = create(absoluteUri);
                }
                this.schemas.put(uri, new Schema(uri, baseNode, parentSchema, true));
            } else {
                this.schemas.put(uri, new Schema(uri, baseNode, null, true));
            }
        }
        List<JsonNode> refs = baseNode.findValues("$ref");
        for (JsonNode ref : refs) {
            if (ref.isValueNode()) {
                String refVal = ref.asText();
                URI refUri = null;
                try {
                    refUri = URI.create(refVal);
                } catch (Exception ex) {
                    LOGGER.info("Exception: {}", ex.getMessage());
                }
                if (refUri != null && !getByUri(refUri).isPresent()) {
                    if (refUri.isAbsolute()) {
                        create(refUri);
                    } else {
                        create(baseUri.resolve(refUri));
                    }
                }
            }
        }
    }

    return this.schemas.get(uri);
}

From source file:org.apache.syncope.client.console.panels.ImplementationModalPanel.java

public ImplementationModalPanel(final BaseModal<ImplementationTO> modal, final ImplementationTO implementation,
        final PageReference pageRef) {

    super(modal, pageRef);
    this.implementation = implementation;
    this.viewMode = implementation.getEngine() == ImplementationEngine.GROOVY ? ViewMode.GROOVY_BODY
            : implementation.getType() == ImplementationType.REPORTLET
                    || implementation.getType() == ImplementationType.ACCOUNT_RULE
                    || implementation.getType() == ImplementationType.PASSWORD_RULE
                    || implementation.getType() == ImplementationType.PULL_CORRELATION_RULE ? ViewMode.JSON_BODY
                            : ViewMode.JAVA_CLASS;
    this.create = implementation.getKey() == null;

    add(new AjaxTextFieldPanel("key", "key", new PropertyModel<>(implementation, "key"), false)
            .addRequiredLabel().setEnabled(create));

    List<String> classes = Collections.emptyList();
    if (viewMode == ViewMode.JAVA_CLASS) {
        Optional<JavaImplInfo> javaClasses = SyncopeConsoleSession.get().getPlatformInfo()
                .getJavaImplInfo(implementation.getType());
        classes = javaClasses.isPresent() ? new ArrayList<>(javaClasses.get().getClasses()) : new ArrayList<>();
    } else if (viewMode == ViewMode.JSON_BODY) {
        ClassPathScanImplementationLookup implementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication
                .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP);

        switch (implementation.getType()) {
        case REPORTLET:
            classes = implementationLookup.getReportletConfs().keySet().stream().collect(Collectors.toList());
            break;

        case ACCOUNT_RULE:
            classes = implementationLookup.getAccountRuleConfs().keySet().stream().collect(Collectors.toList());
            break;

        case PASSWORD_RULE:
            classes = implementationLookup.getPasswordRuleConfs().keySet().stream()
                    .collect(Collectors.toList());
            break;

        case PULL_CORRELATION_RULE:
            classes = implementationLookup.getPullCorrelationRuleConfs().keySet().stream()
                    .collect(Collectors.toList());
            break;

        default:/*w ww  .  j  av  a 2s  .c o  m*/
        }
    }
    Collections.sort(classes);

    AjaxDropDownChoicePanel<String> javaClass = new AjaxDropDownChoicePanel<>("javaClass", "Class",
            new PropertyModel<>(implementation, "body"));
    javaClass.setNullValid(false);
    javaClass.setChoices(classes);
    javaClass.addRequiredLabel();
    javaClass.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true);
    javaClass.setVisible(viewMode == ViewMode.JAVA_CLASS);
    add(javaClass);

    AjaxDropDownChoicePanel<String> jsonClass = new AjaxDropDownChoicePanel<>("jsonClass", "Class",
            new Model<>());
    jsonClass.setNullValid(false);
    jsonClass.setChoices(classes);
    jsonClass.addRequiredLabel();
    jsonClass.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true);
    jsonClass.setVisible(viewMode == ViewMode.JSON_BODY);
    if (viewMode == ViewMode.JSON_BODY && StringUtils.isNotBlank(implementation.getBody())) {
        try {
            JsonNode node = MAPPER.readTree(implementation.getBody());
            if (node.has("@class")) {
                jsonClass.setModelObject(node.get("@class").asText());
            }
        } catch (IOException e) {
            LOG.error("Could not parse as JSON payload: {}", implementation.getBody(), e);
        }
    }
    jsonClass.setReadOnly(jsonClass.getModelObject() != null);
    add(jsonClass);

    WebMarkupContainer groovyClassContainer = new WebMarkupContainer("groovyClassContainer");
    groovyClassContainer.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true);
    groovyClassContainer.setVisible(viewMode != ViewMode.JAVA_CLASS);
    add(groovyClassContainer);

    if (StringUtils.isBlank(implementation.getBody())
            && implementation.getEngine() == ImplementationEngine.GROOVY) {

        String templateClassName = null;

        switch (implementation.getType()) {
        case REPORTLET:
            templateClassName = "MyReportlet";
            break;

        case ACCOUNT_RULE:
            templateClassName = "MyAccountRule";
            break;

        case PASSWORD_RULE:
            templateClassName = "MyPasswordRule";
            break;

        case ITEM_TRANSFORMER:
            templateClassName = "MyItemTransformer";
            break;

        case TASKJOB_DELEGATE:
            templateClassName = "MySchedTaskJobDelegate";
            break;

        case RECON_FILTER_BUILDER:
            templateClassName = "MyReconFilterBuilder";
            break;

        case LOGIC_ACTIONS:
            templateClassName = "MyLogicActions";
            break;

        case PROPAGATION_ACTIONS:
            templateClassName = "MyPropagationActions";
            break;

        case PULL_ACTIONS:
            templateClassName = "MyPullActions";
            break;

        case PUSH_ACTIONS:
            templateClassName = "MyPushActions";
            break;

        case PULL_CORRELATION_RULE:
            templateClassName = "MyPullCorrelationRule";
            break;

        case VALIDATOR:
            templateClassName = "MyValidator";
            break;

        case RECIPIENTS_PROVIDER:
            templateClassName = "MyRecipientsProvider";
            break;

        default:
        }

        if (templateClassName != null) {
            try {
                implementation.setBody(StringUtils.substringAfter(IOUtils.toString(
                        getClass().getResourceAsStream("/org/apache/syncope/client/console/implementations/"
                                + templateClassName + ".groovy")),
                        "*/\n"));
            } catch (IOException e) {
                LOG.error("Could not load the expected Groovy template {} for {}", templateClassName,
                        implementation.getType(), e);
            }
        }
    }

    TextArea<String> groovyClass = new TextArea<>("groovyClass", new PropertyModel<>(implementation, "body"));
    groovyClass.setMarkupId("groovyClass").setOutputMarkupPlaceholderTag(true);
    groovyClass.setVisible(viewMode != ViewMode.JAVA_CLASS);
    groovyClass.setRequired(true);
    groovyClassContainer.add(groovyClass);

    jsonClass.add(new AjaxEventBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = 5538299138211283825L;

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            ClassPathScanImplementationLookup implementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication
                    .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP);

            Class<?> clazz = null;
            switch (implementation.getType()) {
            case REPORTLET:
                clazz = implementationLookup.getReportletConfs().get(jsonClass.getModelObject());
                break;

            case ACCOUNT_RULE:
                clazz = implementationLookup.getAccountRuleConfs().get(jsonClass.getModelObject());
                break;

            case PASSWORD_RULE:
                clazz = implementationLookup.getPasswordRuleConfs().get(jsonClass.getModelObject());
                break;

            case PULL_CORRELATION_RULE:
                clazz = implementationLookup.getPullCorrelationRuleConfs().get(jsonClass.getModelObject());
                break;

            default:
            }

            if (clazz != null) {
                try {
                    target.appendJavaScript("editor.getDoc().setValue('"
                            + MAPPER.writeValueAsString(clazz.newInstance()) + "');");
                } catch (Exception e) {
                    LOG.error("Could not generate a value for {}", jsonClass.getModelObject(), e);
                }
            }
        }
    });
}

From source file:org.apache.syncope.client.console.SyncopeConsoleApplication.java

@SuppressWarnings("unchecked")
protected void populatePageClasses(final Properties props) {
    Enumeration<String> propNames = (Enumeration<String>) props.propertyNames();
    while (propNames.hasMoreElements()) {
        String name = propNames.nextElement();
        if (name.startsWith("page.")) {
            try {
                Class<?> clazz = ClassUtils.getClass(props.getProperty(name));
                if (BasePage.class.isAssignableFrom(clazz)) {
                    pageClasses.put(StringUtils.substringAfter("page.", name),
                            (Class<? extends BasePage>) clazz);
                } else {
                    LOG.warn("{} does not extend {}, ignoring...", clazz.getName(), BasePage.class.getName());
                }/*from ww w .j  a v a 2s  .c  o m*/
            } catch (ClassNotFoundException e) {
                LOG.error("While looking for class identified by property '{}'", name, e);
            }
        }
    }
}