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

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

Introduction

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

Prototype

public static String substringBetween(String str, String tag) 

Source Link

Document

Gets the String that is nested in between two instances of the same String.

Usage

From source file:fr.dutra.tools.maven.deptree.core.DotParser.java

private void parseFirstLine() {
    String str = StringUtils.substringBetween(this.lines.get(0), "\"");
    String[] tokens = StringUtils.split(str, ':');
    if (tokens.length != 4) {
        throw new IllegalStateException(
                "Wrong number of tokens: " + tokens.length + " for first line (4 expected)");
    }//from   w w w .  j  a  va 2s.c  o  m
    final Node node = new Node(tokens[0], tokens[1], tokens[2], null, tokens[3], null, null, false);
    root = node;
    nodes.put(str, node);
    lineIndex++;
}

From source file:fr.dutra.tools.maven.deptree.core.TgfParser.java

/**
 * sample line structure://ww w  .j  a  v  a2s. c o m
 * <pre>
 * -1437430659 com.ibm:mqjms:jar:6.0.0:runtime
 * #
 * 1770590530 96632433 compile
 * </pre>
 */
private void parseLine() {
    String line = this.lines.get(this.lineIndex);
    if ("#".equals(line)) {
        this.phase = ParsePhase.EDGE;
    } else if (this.phase == ParsePhase.NODE) {
        String id = StringUtils.substringBefore(line, " ");
        String artifact;
        if (line.contains("active project artifact:")) {
            artifact = extractActiveProjectArtifact();
        } else {
            artifact = StringUtils.substringAfter(line, " ");
        }
        Node node = parseArtifactString(artifact);
        if (root == null) {
            this.root = node;
        }
        nodes.put(id, node);
    } else {
        String parentId = StringUtils.substringBefore(line, " ");
        String childId = StringUtils.substringBetween(line, " ");
        Node parent = nodes.get(parentId);
        Node child = nodes.get(childId);
        parent.addChildNode(child);
    }
}

From source file:fr.dutra.tools.maven.deptree.core.DotParser.java

/**
 * sample line structure:// w  w  w  .j  a v a  2s  . com
 * <pre>"fr.dutra.tools.maven.deptree.core:maven-dependency-tree-parser:jar:1.0-SNAPSHOT" -> "org.mockito:mockito-all:jar:1.8.5:test" ;</pre>
 */
private void parseLine() {
    String line = this.lines.get(this.lineIndex);
    String parentArtifact;
    if (line.contains("->")) {
        parentArtifact = StringUtils.substringBetween(line, "\"");
    } else {
        parentArtifact = extractActiveProjectArtifact();
        line = lines.get(lineIndex);
    }
    Node parent = nodes.get(parentArtifact);
    if (parent != null) {
        String childArtifact;
        if (line.contains("active project artifact:")) {
            childArtifact = extractActiveProjectArtifact();
        } else {
            childArtifact = StringUtils.substringBetween(line, "-> \"", "\" ;");
        }
        Node child = parseArtifactString(childArtifact);
        parent.addChildNode(child);
        nodes.put(childArtifact, child);
    } else {
        throw new IllegalStateException("Cannot find parent artifact: " + parentArtifact);
    }

}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.RequestAttributeResolver.java

public Set<String> resolve(String filter) {
    Set<String> ret = new LinkedHashSet<>();
    // only display results if filter contains @
    if (!StringUtils.contains(text, "@") || !StringUtils.contains(text, "data-sly-use")) {
        return ret;
    }/*w ww . j  a  v  a2s  . co m*/
    ElementUtilities.ElementAcceptor acceptor = new ElementUtilities.ElementAcceptor() {
        @Override
        public boolean accept(Element e, TypeMirror type) {
            // we are looking for the annotations
            for (AnnotationMirror mirror : e.getAnnotationMirrors()) {
                if (mirror.getAnnotationType() != null && mirror.getAnnotationType().asElement() != null
                        && StringUtils.equalsIgnoreCase(REQUEST_ATTRIBUTE_CLASSNAME,
                                mirror.getAnnotationType().asElement().toString())) {
                    return true;
                }
            }
            return false;
        }
    };
    String clazz = StringUtils.substringBetween(text, "'");

    Set<Element> elems = getMembersFromJavaSource(clazz, acceptor);
    for (Element elem : elems) {
        if (StringUtils.startsWithIgnoreCase(elem.getSimpleName().toString(), filter)
                && !StringUtils.contains(text, elem.getSimpleName().toString() + " ")
                && !StringUtils.contains(text, elem.getSimpleName().toString() + "=")) {
            ret.add(elem.getSimpleName().toString());
        }
    }
    if (ret.isEmpty()) {
        for (String att : getAttributesFromClassLoader(clazz)) {
            if (StringUtils.startsWithIgnoreCase(att, filter) && !StringUtils.contains(text, att + " ")
                    && !StringUtils.contains(text, att + "=")) {
                ret.add(att);
            }
        }
    }
    return ret;
}

From source file:com.google.gdt.eclipse.designer.smart.model.CanvasSizeSupport.java

/**
 * @return the {@link Integer} value if given size string is integer, else <code>null</code>.
 *//*from   ww w. j av a 2s  .  c o m*/
static Integer getIntegerValue(String s) {
    s = StringUtils.substringBetween(s, "\"");
    s = StringUtils.substringBeforeLast(s, "px");
    try {
        return Integer.valueOf(s);
    } catch (NumberFormatException e) {
    }
    return null;
}

From source file:opennlp.tools.similarity.apps.GoogleAutoCompleteQueryRunner.java

public List<String> getAutoCompleteExpression(String rawExpr) {
    // insert spaces into camel cases
    rawExpr = rawExpr.replaceAll("([a-z][a-z])([A-Z][a-z])", "$1 $2");
    String query = rawExpr.replace(' ', '+');
    try {/*  w  ww . j ava2  s.  c om*/
        query = URLEncoder.encode(query, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String pageOrigHTML = pageFetcher.fetchOrigHTML(searchRequest + query + suffix);
    String[] results = StringUtils.substringsBetween(pageOrigHTML, "<CompleteSuggestion>",
            "</CompleteSuggestion>");
    List<List<String>> accum = new ArrayList<List<String>>();
    if (results == null)
        return null;
    for (String wrapped : results) {
        List<String> accumCase = new ArrayList<String>();
        String[] words = null;
        try {
            words = StringUtils.substringBetween(wrapped, "\"").split(" ");
        } catch (Exception e) {

        }
        if (words == null || words.length < 1)
            continue;
        accumCase = Arrays.asList(words);
        accum.add(accumCase);
    }

    //TODO make more noise-resistant algo
    if (accum.size() > 1) {
        List<String> first = new ArrayList<String>(accum.get(0));
        List<String> second = new ArrayList<String>(accum.get(1));

        first.retainAll(second);
        if (first.size() > 0)
            return first;
        else
            return accum.get(0);
    }

    if (accum.size() == 1)
        return accum.get(0);

    return null;
}

From source file:org.ebayopensource.turmeric.repositorysystem.imp.impl.TurmericOrganizationProvider.java

/**
 * {@inheritDoc}/*from w ww .j a v  a  2  s .c o  m*/
 */
public String getNamespacePartFromTargetNamespace(String targetNamespace) {
    if (StringUtils.isNotBlank(targetNamespace)
            && targetNamespace.startsWith(TurmericConstants.DEFAULT_SERVICE_NAMESPACE_PREFIX)) {
        //it could be following the Marketplace format
        boolean matches = Pattern.matches(TurmericConstants.TURMERIC_NAMESPACE_PATTERN, targetNamespace);
        if (matches == true) {
            if (SOALogger.DEBUG) {
                logger.debug("The target namespace is following the Turmeric recommended format->",
                        targetNamespace);
            }
            targetNamespace = StringUtils.substringAfter(targetNamespace,
                    TurmericConstants.DEFAULT_SERVICE_NAMESPACE_PREFIX);
            return StringUtils.substringBetween(targetNamespace, "/");
        } else {
            if (SOALogger.DEBUG) {
                logger.warning("The target namespace is NOT following the Marketpalce format->",
                        targetNamespace);
            }
        }

    }
    return "";
}

From source file:org.eclipse.jubula.tools.internal.serialisation.XStreamXmlSerializer.java

/**
 * checks if xml file has supported Version
 * @param header XML Header//  w w w .ja  v a2  s  .  co  m
 */
private void checkVersion(String header) {
    if (header.indexOf("minor") == -1 //$NON-NLS-1$
            || header.indexOf("major") == -1) { //$NON-NLS-1$
        return;
    }
    String minor = header.substring(header.indexOf("minor"), //$NON-NLS-1$
            header.indexOf("major")); //$NON-NLS-1$ 
    String major = header.substring(header.indexOf("major")); //$NON-NLS-1$
    StringUtils.substringBetween(minor, StringConstants.QUOTE);
    StringUtils.substringBetween(major, StringConstants.QUOTE);
}

From source file:org.eclipse.wb.internal.rcp.databinding.ui.contentproviders.ObservableDetailUiContentProvider.java

public void updateFromObject() throws Exception {
    String propertyReference = m_observable.getDetailPropertyReference();
    // sets property reference and type
    if (propertyReference == null) {
        // calculate type over viewer input element type
        if (m_observable.getMasterObservable() instanceof ViewerObservableInfo) {
            Class<?> elementType = AbstractViewerInputBindingInfo
                    .getViewerInutElementType(m_observable.getMasterObservable(), m_provider);
            if (elementType == null) {
                calculateFinish();/*from   w  w  w .  j a  va  2  s .  c o  m*/
            } else {
                setClassName(CoreUtils.getClassName(elementType));
            }
        } else {
            calculateFinish();
        }
    } else if (m_observable.getDetailBeanClass() == null) {
        // prepare property
        Class<?> propertyType = m_observable.getDetailPropertyType();
        String propertyName = StringUtils.substringBetween(propertyReference, "\"");
        BeanPropertyBindableInfo bindableProperty = new BeanPropertyBindableInfo(null, null, propertyName,
                propertyType, propertyName);
        bindableProperty.setProperties(Collections.<PropertyBindableInfo>emptyList());
        PropertyAdapter property = new ObservePropertyAdapter(null, bindableProperty);
        // prepare fake class name
        String className = "detail(" + propertyReference + ", " + ClassUtils.getShortClassName(propertyType)
                + ".class)";
        // sets class and property
        setClassNameAndProperty(className, property, false);
    } else {
        // set temporally None strategy for select detail property
        LoadedPropertiesCheckedStrategy strategy = m_configuration.getLoadedPropertiesCheckedStrategy();
        m_configuration.setLoadedPropertiesCheckedStrategy(LoadedPropertiesCheckedStrategy.None);
        // sets class and property
        setClassNameAndProperties(m_observable.getDetailBeanClass(), null,
                Lists.newArrayList(propertyReference));
        // restore strategy
        m_configuration.setLoadedPropertiesCheckedStrategy(strategy);
    }
}

From source file:org.jahia.services.seo.jcr.VanityUrlMapper.java

/**
 * checks if a vanity exists and put the result as an attribute of the request
 * this is used in urlRewriting rules//from w  ww  .j  a  v  a  2s.c  o  m
 * @param hsRequest
 *              the request used during urlRewriting operations
 * @param outboundUrl
 *              the url received to be checked
 */
public void checkVanityUrl(HttpServletRequest hsRequest, String outboundContext, String outboundUrl) {
    hsRequest.removeAttribute(VANITY_KEY);

    URLResolverFactory urlResolverFactory = (URLResolverFactory) SpringContextSingleton
            .getBean("urlResolverFactory");
    VanityUrlService vanityUrlService = (VanityUrlService) SpringContextSingleton
            .getBean("org.jahia.services.seo.jcr.VanityUrlService");

    String ctx = StringUtils.defaultIfEmpty(hsRequest.getContextPath(), "");
    String fullUrl = ctx + Render.getRenderServletPath() + outboundUrl;
    hsRequest.setAttribute(VANITY_KEY, fullUrl);

    if (StringUtils.isNotEmpty(outboundUrl) && !Url.isLocalhost(hsRequest.getServerName())) {
        String serverName = null;
        String siteKey = null;
        String contextToCheck = outboundContext;
        int schemaDelimiterIndex = outboundContext.indexOf("://");
        if (schemaDelimiterIndex != -1) {
            try {
                URI uri = new URI(outboundContext);
                siteKey = lookupSiteKeyByServerName(uri.getHost());
                if (siteKey != null) {
                    contextToCheck = uri.getPath();
                    StringBuffer sb = new StringBuffer().append(uri.getScheme()).append("://")
                            .append(uri.getHost());
                    if (uri.getPort() != -1) {
                        sb.append(':').append(uri.getPort());
                    }
                    serverName = sb.toString();
                }
            } catch (URISyntaxException e) {
                // simply continue as siteKey will be determined later
            }
        } else if (StringUtils.isNotEmpty(
                (String) hsRequest.getAttribute(ServerNameToSiteMapper.ATTR_NAME_SERVERNAME_FOR_LINK))) {
            String host = (String) hsRequest.getAttribute(ServerNameToSiteMapper.ATTR_NAME_SERVERNAME_FOR_LINK);
            host = StringUtils.substringBefore(StringUtils.substringAfter(host, "://"), ":");
            siteKey = lookupSiteKeyByServerName(host);
        }
        if (StringUtils.equals(ctx, contextToCheck)) {
            String url = "/render" + outboundUrl;
            try {
                url = URLDecoder.decode(url, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // shouldn't happen
                throw new RuntimeException(e);
            }
            URLResolver urlResolver = urlResolverFactory.createURLResolver(url, hsRequest.getServerName(),
                    hsRequest);
            try {
                JCRNodeWrapper node = urlResolver.getNode();
                if (urlResolver.isMapped()) {
                    RenderContext context = (RenderContext) hsRequest.getAttribute("renderContext");
                    if (siteKey == null) {
                        siteKey = context != null ? context.getSite().getSiteKey()
                                : node.getResolveSite().getSiteKey();
                    }
                    VanityUrl vanityUrl = vanityUrlService.getVanityUrlForWorkspaceAndLocale(node,
                            urlResolver.getWorkspace(), urlResolver.getLocale(), siteKey);
                    if (vanityUrl != null && vanityUrl.isActive()) {
                        //for macros some parameters added (like ##requestParameters## for languageswitcher)
                        String macroExtension = "";
                        if (fullUrl.matches("(.?)*##[a-zA-Z]*##$")) {
                            macroExtension = "##" + StringUtils.substringBetween(fullUrl, "##") + "##";
                        }
                        hsRequest.setAttribute(VANITY_KEY, ctx + Render.getRenderServletPath() + "/"
                                + urlResolver.getWorkspace() + vanityUrl.getUrl() + macroExtension);
                        if (serverName != null) {
                            hsRequest.setAttribute(ServerNameToSiteMapper.ATTR_NAME_SERVERNAME_FOR_LINK,
                                    serverName);
                        }
                    }
                }
            } catch (RepositoryException e) {
                logger.debug("Error when trying to obtain vanity url", e);
                if (serverName != null) {
                    hsRequest.setAttribute(ServerNameToSiteMapper.ATTR_NAME_SERVERNAME_FOR_LINK, serverName);
                }
            }
        }
    }
}