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 open, String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:net.sourceforge.pmd.lang.apex.ast.ASTAnnotation.java

@Override
public String getImage() {
    String result = StringUtils.substringBetween(node.toString(), "value = ", ")");
    return result;
}

From source file:net.sourceforge.pmd.lang.apex.ast.ASTAnnotationParameter.java

@Override
public String getImage() {
    String result = null;/* ww w.j a va 2  s . c o m*/

    if (node.getValue() != null) {
        result = node.getValue().toString();
        result = StringUtils.substringBetween(result, "value = ", ")");
    }

    return result;
}

From source file:net.ymate.framework.core.taglib.ui.ScriptTag.java

@Override
public int doEndTag() throws JspException {
    StringBuilder _scriptTmpl = new StringBuilder("<script");
    if (StringUtils.isNotBlank(this.getId())) {
        _scriptTmpl.append(" id=\"").append(this.getId()).append("\"");
    }/* w  w w  .ja v  a 2s  .  c  o m*/
    boolean _isEmpty = true;
    if (StringUtils.isNotBlank(this.getSrc())) {
        _scriptTmpl.append(" src=\"").append(this.getSrc()).append("\"");
        _isEmpty = false;
    }
    _scriptTmpl.append(" type=\"").append(StringUtils.defaultIfBlank(this.getType(), "text/javascript"))
            .append("\">");
    if (_isEmpty && StringUtils.isNotEmpty(this.getValue())) {
        String _wrapper = StringUtils.defaultIfBlank(this.getWrapper(), "script");
        String _content = StringUtils.substringBetween(this.getValue(), "<" + _wrapper + ">",
                "</" + _wrapper + ">");
        if (StringUtils.isNotBlank(_content)) {
            this.setValue(_content);
        }
        _scriptTmpl.append(this.getValue()).append("\n");
        _isEmpty = false;
    }
    _scriptTmpl.append("</script>\n");
    if (!_isEmpty) {
        __ui.writerToScriptPart(_scriptTmpl.toString());
    }
    //
    this.__ui = null;
    this.src = null;
    this.value = null;
    this.id = null;
    this.type = null;
    this.wrapper = null;
    return super.doEndTag();
}

From source file:net.ymate.module.oauth.connector.impl.QQConnectProcessor.java

@Override
protected JSONObject __doParseConnectResponseBody(IHttpResponse response) throws Exception {
    if (response != null && response.getStatusCode() == HttpServletResponse.SC_OK) {
        JSONObject _result = null;//  w  w  w.jav a2  s . c o  m
        if (StringUtils.startsWith(response.getContent(), "callback")) {
            _result = JSON.parseObject(StringUtils.substringBetween(response.getContent(), "callback(", ");"));
        } else {
            _result = new JSONObject();
            _result.putAll(ParamUtils.parseQueryParamStr(response.getContent(), true, "UTF-8"));
        }
        if (_result.containsKey("error")) {
            throw new RuntimeException(_result.toJSONString());
        }
        return _result;
    }
    return null;
}

From source file:net.ymate.platform.commons.util.ClassUtils.java

@SuppressWarnings("unchecked")
protected static <T> void __doFindClassByZip(Collection<Class<T>> collections, Class<T> clazz,
        String packageName, URL zipUrl, Class<?> callingClass) {
    ZipInputStream _zipStream = null;
    try {/* ww w.  j ava2  s  .  c o  m*/
        String _zipFilePath = zipUrl.toString();
        if (_zipFilePath.indexOf('!') > 0) {
            _zipFilePath = StringUtils.substringBetween(zipUrl.toString(), "zip:", "!");
        } else {
            _zipFilePath = StringUtils.substringAfter(zipUrl.toString(), "zip:");
        }
        _zipStream = new ZipInputStream(new FileInputStream(new File(_zipFilePath)));
        ZipEntry _zipEntry = null;
        while (null != (_zipEntry = _zipStream.getNextEntry())) {
            if (!_zipEntry.isDirectory()) {
                if (_zipEntry.getName().endsWith(".class") && _zipEntry.getName().indexOf('$') < 0) {
                    Class<?> _class = __doProcessEntry(zipUrl, _zipEntry);
                    if (_class != null) {
                        if (clazz.isAnnotation()) {
                            if (isAnnotationOf(_class, (Class<Annotation>) clazz)) {
                                collections.add((Class<T>) _class);
                            }
                        } else if (clazz.isInterface()) {
                            if (isInterfaceOf(_class, clazz)) {
                                collections.add((Class<T>) _class);
                            }
                        } else if (isSubclassOf(_class, clazz)) {
                            collections.add((Class<T>) _class);
                        }
                    }
                }
            }
            _zipStream.closeEntry();
        }
    } catch (Exception e) {
        _LOG.warn("", RuntimeUtils.unwrapThrow(e));
    } finally {
        if (_zipStream != null) {
            try {
                _zipStream.close();
            } catch (IOException e) {
                _LOG.warn("", RuntimeUtils.unwrapThrow(e));
            }
        }
    }
}

From source file:net.ymate.platform.commons.util.ClassUtils.java

/**
 * @param clazz //from   w  ww . jav  a2s .  c o  m
 * @return 
 */
public static Class<?> getArrayClassType(Class<?> clazz) {
    try {
        return Class.forName(StringUtils.substringBetween(clazz.getName(), "[L", ";"));
    } catch (ClassNotFoundException e) {
        _LOG.warn("", RuntimeUtils.unwrapThrow(e));
    }
    return null;
}

From source file:net.ymate.platform.core.beans.impl.DefaultBeanLoader.java

private List<Class<?>> __doFindClassByZip(URL zipUrl, IBeanFilter filter) throws Exception {
    List<Class<?>> _returnValue = new ArrayList<Class<?>>();
    ZipInputStream _zipStream = null;
    try {/*from  w  w  w  .  ja  v  a 2s.co  m*/
        String _zipFilePath = zipUrl.toString();
        if (_zipFilePath.indexOf('!') > 0) {
            _zipFilePath = StringUtils.substringBetween(zipUrl.toString(), "zip:", "!");
        } else {
            _zipFilePath = StringUtils.substringAfter(zipUrl.toString(), "zip:");
        }
        File _zipFile = new File(_zipFilePath);
        if (!__doCheckExculedFile(_zipFile.getName())) {
            _zipStream = new ZipInputStream(new FileInputStream(_zipFile));
            ZipEntry _zipEntry = null;
            while (null != (_zipEntry = _zipStream.getNextEntry())) {
                if (!_zipEntry.isDirectory()) {
                    if (_zipEntry.getName().endsWith(".class") && _zipEntry.getName().indexOf('$') < 0) {
                        String _className = StringUtils.substringBefore(_zipEntry.getName().replace("/", "."),
                                ".class");
                        __doAddClass(_returnValue, __doLoadClass(_className), filter);
                    }
                }
                _zipStream.closeEntry();
            }
        }
    } finally {
        if (_zipStream != null) {
            try {
                _zipStream.close();
            } catch (IOException ignored) {
            }
        }
    }
    return _returnValue;
}

From source file:net.ymate.platform.mvc.web.support.RequestMappingParser.java

/**
 * @param mappingParamPart ?//from w ww  .  j  a v a  2 s.c  o m
 * @param mappingMatcher ??
 * @return ?mappingMatcher????
 */
protected Map<String, String> parserMappingParams(String mappingParamPart, String mappingMatcher) {
    Map<String, String> _params = new HashMap<String, String>();
    String[] _paramNames = StringUtils.split(mappingMatcher, "/");
    String[] _parts = StringUtils.split(mappingParamPart, "/");
    if (_parts.length >= _paramNames.length) {
        for (int _index = 0; _index < _paramNames.length; _index++) {
            String _pName = StringUtils.substringBetween(_paramNames[_index], "{", "}");
            if (_pName != null) {
                _params.put(_pName, _parts[_index]);
            }
        }
    }
    return _params;
}

From source file:net.ymate.platform.plugin.impl.DefaultPluginParser.java

private PluginMeta __doPluginElementProcess(ClassLoader classLoader, Element pluginElement, String pluginPath,
        URL configFileUrl) {/*from ww  w  . j a  v  a  2 s  .c  om*/
    String id = pluginElement.getAttribute(ATTR_ID);
    String name = pluginElement.getAttribute(ATTR_NAME);
    String alias = pluginElement.getAttribute(ATTR_ALIAS);
    String version = pluginElement.getAttribute(ATTR_VERSION);
    String initClass = pluginElement.getAttribute(ATTR_CLASS);
    if ((StringUtils.isBlank(alias) || StringUtils.isBlank(name)) && StringUtils.isBlank(initClass)) {
        _LOG.warn(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.plugin.plugin_will_be_ignored",
                configFileUrl.getFile()));
        return null;
    }
    if (StringUtils.isBlank(id)) {
        // ?ID???MD5??ID
        id = DigestUtils.md5Hex(initClass);
    }
    //
    boolean disabled = false;
    NodeList _disabledNodes = pluginElement.getElementsByTagName(ATTR_DISABLED);
    if (_disabledNodes.getLength() > 0) {
        Node _node = _disabledNodes.item(0);
        disabled = new BlurObject(_node.getTextContent()).toBooleanValue();
    }
    if (disabled) {
        _LOG.warn(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.plugin.plugin_will_be_disabled",
                configFileUrl.getFile()));
        return null;
    }
    String author = pluginElement.getAttribute(ATTR_AUTHOR);
    String email = pluginElement.getAttribute(ATTR_EMAIL);
    String description = "";
    NodeList _descriptionNodes = pluginElement.getElementsByTagName(ATTR_DESCRIPTION);
    if (_descriptionNodes.getLength() > 0) {
        Node _node = _descriptionNodes.item(0);
        description = _node.getTextContent();
    }
    boolean automatic = true;
    NodeList _automacticNodes = pluginElement.getElementsByTagName(ATTR_AUTOMATIC);
    if (_automacticNodes.getLength() > 0) {
        Node _node = _automacticNodes.item(0);
        automatic = new BlurObject(_node.getTextContent()).toBooleanValue();
    }
    Object _extraObj = null;
    if (__pluginFactory.getPluginConfig().getPluginExtraParserClassImpl() != null) {
        NodeList _extraNodes = pluginElement.getElementsByTagName(ATTR_EXTRA_PART);
        if (_extraNodes.getLength() > 0) {
            _extraObj = __pluginFactory.getPluginConfig().getPluginExtraParserClassImpl()
                    .doExtarParser(_extraNodes.item(0));
        }
    }
    PluginMeta _pluginMeta = new PluginMeta(classLoader, id, name, alias, initClass, version, pluginPath,
            author, email, _extraObj, description);
    _pluginMeta.setAutomatic(automatic);
    _pluginMeta.setDisabled(disabled);
    if (configFileUrl.getProtocol().equals("jar")) {
        _pluginMeta
                .setPluginFile(new File(StringUtils.substringBetween(configFileUrl.getFile(), "file:", "!")));
    }
    return _pluginMeta;
}

From source file:net.ymate.platform.webmvc.support.RequestMappingParser.java

/**
 * @param mappingParamPart ?//from   w  ww  . j  a va2  s.  c  o  m
 * @param mappingMatcher   ??
 * @return ?mappingMatcher????
 */
private Map<String, String> __doParserMappingParams(String mappingParamPart, String mappingMatcher) {
    Map<String, String> _params = new HashMap<String, String>();
    String[] _paramNames = StringUtils.split(mappingMatcher, "/");
    String[] _parts = StringUtils.split(mappingParamPart, "/");
    if (_parts.length >= _paramNames.length) {
        for (int _index = 0; _index < _paramNames.length; _index++) {
            String _pName = StringUtils.substringBetween(_paramNames[_index], "{", "}");
            if (_pName != null) {
                _params.put(_pName, _parts[_index]);
            }
        }
    }
    return _params;
}