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

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

Introduction

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

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:net.ymate.framework.core.util.WebUtils.java

/**
 * @param url           URL?/*from  w  w  w.  java2s.  c  om*/
 * @param needStartWith ?'/'
 * @param needEndwith   ?'/'?
 * @return ?URL?
 */
public static String fixURL(String url, boolean needStartWith, boolean needEndwith) {
    url = StringUtils.trimToNull(url);
    if (url != null) {
        if (needStartWith && !StringUtils.startsWith(url, "/")) {
            url = '/' + url;
        } else if (!needStartWith && StringUtils.startsWith(url, "/")) {
            url = StringUtils.substringAfter(url, "/");
        }
        if (needEndwith && !StringUtils.endsWith(url, "/")) {
            url = url + '/';
        } else if (!needEndwith && StringUtils.endsWith(url, "/")) {
            url = StringUtils.substringBeforeLast(url, "/");
        }
        return url;
    }
    return "";
}

From source file:net.ymate.framework.unpack.Unpackers.java

private boolean __unpack(JarFile jarFile, String prefixPath) throws Exception {
    boolean _results = false;
    Enumeration<JarEntry> _entriesEnum = jarFile.entries();
    for (; _entriesEnum.hasMoreElements();) {
        JarEntry _entry = _entriesEnum.nextElement();
        if (StringUtils.startsWith(_entry.getName(), prefixPath)) {
            if (!_entry.isDirectory()) {
                _LOG.info("Synchronizing resource file: " + _entry.getName());
                //
                String _entryName = StringUtils.substringAfter(_entry.getName(), prefixPath);
                File _targetFile = new File(RuntimeUtils.getRootPath(false), _entryName);
                _targetFile.getParentFile().mkdirs();
                IOUtils.copyLarge(jarFile.getInputStream(_entry), new FileOutputStream(_targetFile));
                _results = true;/*  ww  w. ja  v a  2s . co m*/
            }
        }
    }
    return _results;
}

From source file:net.ymate.module.webproxy.support.DispatchProxyFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    request.setCharacterEncoding(__charsetEncoding);
    response.setCharacterEncoding(__charsetEncoding);
    ////from w  w  w.j av a  2 s . co  m
    response.setContentType(
            Type.ContentType.HTML.getContentType().concat("; charset=").concat(__charsetEncoding));
    //
    HttpServletRequest _request = new RequestMethodWrapper((HttpServletRequest) request, __requestMethodParam);
    HttpServletResponse _response = (HttpServletResponse) response;
    IRequestContext _requestContext = new DefaultRequestContext(_request, __requestPrefix);
    if (null == __ignorePatern || !__ignorePatern.matcher(_requestContext.getOriginalUrl()).find()) {
        if (StringUtils.isNotBlank(__prefix)
                && !StringUtils.startsWith(_requestContext.getRequestMapping(), __prefix)
                || __doMatchBlacklist(_requestContext.getRequestMapping())) {
            _response = new GenericResponseWrapper(_response);
            GenericDispatcher.create(WebMVC.get()).execute(_requestContext, __filterConfig.getServletContext(),
                    _request, _response);
        } else {
            try {
                YMP.get().getEvents()
                        .fireEvent(new WebProxyEvent(WebProxy.get(), WebProxyEvent.EVENT.REQUEST_RECEIVED)
                                .addParamExtend(IEvent.EVENT_SOURCE, _requestContext));
                //
                String _requestMapping = _requestContext.getRequestMapping();
                if (StringUtils.isNotBlank(__prefix)) {
                    _requestMapping = StringUtils.substringAfter(_requestMapping, __prefix);
                }
                StringBuilder _url = new StringBuilder(WebProxy.get().getModuleCfg().getServiceBaseUrl())
                        .append(_requestMapping);
                if (Type.HttpMethod.GET.equals(_requestContext.getHttpMethod())) {
                    if (StringUtils.isNotBlank(_request.getQueryString())) {
                        _url.append("?").append(_request.getQueryString());
                    }
                }
                WebProxy.get().transmission(_request, _response, _url.toString(),
                        _requestContext.getHttpMethod());
            } catch (Throwable e) {
                _LOG.warn("An exception occurred: ", RuntimeUtils.unwrapThrow(e));
            } finally {
                YMP.get().getEvents()
                        .fireEvent(new WebProxyEvent(WebProxy.get(), WebProxyEvent.EVENT.REQUEST_COMPLETED)
                                .addParamExtend(IEvent.EVENT_SOURCE, _requestContext));
            }
        }
    } else {
        chain.doFilter(_request, _response);
    }
}

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 {//www  . ja  v a2 s  .c om
        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.configuration.support.PropertyConfigFileHandler.java

@SuppressWarnings("unchecked")
public PropertyConfigFileHandler load(boolean sorted) {
    if (!__loaded) {
        __sorted = sorted;//from   w  w w  .ja  v a2 s  . c o m
        // ????
        if (sorted) {
            __categories = new LinkedHashMap<String, XMLConfigFileHandler.XMLCategory>();
            __rootAttributes = new LinkedHashMap<String, XMLConfigFileHandler.XMLAttribute>();
        } else {
            __categories = new HashMap<String, XMLConfigFileHandler.XMLCategory>();
            __rootAttributes = new HashMap<String, XMLConfigFileHandler.XMLAttribute>();
        }
        //
        Enumeration<String> _propNames = (Enumeration<String>) __rootProps.propertyNames();
        while (_propNames.hasMoreElements()) {
            String _propName = _propNames.nextElement();
            if (StringUtils.startsWith(_propName, XMLConfigFileHandler.TAG_NAME_ROOT)) {
                String _newPropName = StringUtils.substringAfter(_propName,
                        XMLConfigFileHandler.TAG_NAME_ROOT.concat("."));
                // _propArr[0] = categoryName
                // _propArr[1] = propertyName
                // _propArr[2] = attributes
                // _propArr[3] = attrName
                String[] _propArr = StringUtils.split(_newPropName, ".");
                if (_propArr.length > 1) {
                    // 
                    if (_propArr[0].equalsIgnoreCase(TAG_NAME_ATTRIBUTE)) {
                        __rootAttributes.put(_propArr[1], new XMLConfigFileHandler.XMLAttribute(_propArr[1],
                                __rootProps.getProperty(_propName)));
                        continue;
                    }
                    // category, category?, 
                    XMLConfigFileHandler.XMLCategory _category = __categories.get(_propArr[0]);
                    if (_category == null) {
                        _category = new XMLConfigFileHandler.XMLCategory(_propArr[0], null, null, __sorted);
                        __categories.put(_propArr[0], _category);
                    }
                    //
                    if (_propArr.length == 4) {
                        if (_propArr[2].equalsIgnoreCase(TAG_NAME_ATTRIBUTE)) {
                            XMLConfigFileHandler.XMLProperty _prop = __safeGetProperty(_category, _propName,
                                    _propArr[1]);
                            if (_prop != null) {
                                __fixedSetAttribute(_prop, _propName, _propArr[3]);
                            }
                        } else {
                            _category.getPropertyMap().put(_propArr[3], new XMLConfigFileHandler.XMLProperty(
                                    _propArr[3], __rootProps.getProperty(_propName), null));
                        }
                    } else if (_propArr.length == 2) {
                        __fixedSetProperty(_category, _propName, _propArr[1]);
                    } else {
                        if (_propArr[1].equalsIgnoreCase(TAG_NAME_ATTRIBUTE)) {
                            _category.getAttributeMap().put(_propArr[2], new XMLConfigFileHandler.XMLAttribute(
                                    _propArr[2], __rootProps.getProperty(_propName)));
                        } else {
                            XMLConfigFileHandler.XMLProperty _prop = __safeGetProperty(_category, _propName,
                                    _propArr[1]);
                            if (_prop != null) {
                                __fixedSetAttribute(_prop, _propName, _propArr[2]);
                            }
                        }
                    }
                }
            }
        }
        // ??DEFAULT_CATEGORY_NAME??
        if (!__categories.containsKey(XMLConfigFileHandler.DEFAULT_CATEGORY_NAME)) {
            __categories.put(XMLConfigFileHandler.DEFAULT_CATEGORY_NAME, new XMLConfigFileHandler.XMLCategory(
                    XMLConfigFileHandler.DEFAULT_CATEGORY_NAME, null, null, sorted));
        }
        //
        this.__loaded = true;
    }
    return this;
}

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 {// w  w w  . j  a v  a  2 s  .  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.module.JdbcModule.java

public void initialize(final Map<String, String> moduleCfgs) throws Exception {
    final boolean _showSql = new BlurObject(moduleCfgs.get("base.show_sql")).toBooleanValue();
    final Set<JdbcDataSourceCfgMeta> _metas = new HashSet<JdbcDataSourceCfgMeta>();
    for (String _name : StringUtils.split(StringUtils
            .defaultIfEmpty(StringUtils.trimToEmpty(moduleCfgs.get("base.datasource_list")), "default"), "|")) {
        String _adaptorClass = moduleCfgs.get("datasource." + _name + ".adapter_class");
        String _driverClass = moduleCfgs.get("datasource." + _name + ".driver_class");
        String _connectionUrl = moduleCfgs.get("datasource." + _name + ".connection_url");
        String _userName = moduleCfgs.get("datasource." + _name + ".username");
        String _password = moduleCfgs.get("datasource." + _name + ".password");
        ///* w w  w .java 2 s . c  om*/
        Map<String, String> _params = new HashMap<String, String>();
        String _paramKey = "datasource." + _name + ".params.";
        for (String _cfgKey : moduleCfgs.keySet()) {
            if (_cfgKey.startsWith(_paramKey)) {
                _params.put(StringUtils.substringAfter(_cfgKey, _paramKey), moduleCfgs.get(_cfgKey));
            }
        }
        _metas.add(new JdbcDataSourceCfgMeta(_name, _adaptorClass, _driverClass, _connectionUrl, _userName,
                _password, _params));
    }
    JDBC.initialize(new IJdbcConfig() {

        public boolean isShowSql() {
            return _showSql;
        }

        public String getTablePrefix() {
            return moduleCfgs.get("base.table_prefix");
        }

        public String getDefaultDataSourceName() {
            return moduleCfgs.get("base.datasource_default");
        }

        public String[] getRepositoryPackages() {
            return StringUtils.split(moduleCfgs.get("base.repository_packages"), "|");
        }

        public Set<JdbcDataSourceCfgMeta> getDataSourceCfgMetas() {
            return _metas;
        }
    });
}

From source file:net.ymate.platform.module.MongoDBModule.java

public void initialize(final Map<String, String> moduleCfgs) throws Exception {
    final boolean _showLog = new BlurObject(moduleCfgs.get("base.show_log")).toBooleanValue();
    final Set<DataSourceCfgMeta> _metas = new HashSet<DataSourceCfgMeta>();
    for (String _name : StringUtils.split(StringUtils.trimToEmpty(moduleCfgs.get("base.datasource_list")),
            "|")) {
        String _connectionUrl = moduleCfgs.get("datasource." + _name + ".connection_url");
        String _userName = moduleCfgs.get("datasource." + _name + ".username");
        String _password = moduleCfgs.get("datasource." + _name + ".password");
        ///*w ww. j av  a 2s. c o m*/
        Map<String, String> _params = new HashMap<String, String>();
        String _paramKey = "datasource." + _name + ".params.";
        for (String _cfgKey : moduleCfgs.keySet()) {
            if (_cfgKey.startsWith(_paramKey)) {
                _params.put(StringUtils.substringAfter(_cfgKey, _paramKey), moduleCfgs.get(_cfgKey));
            }
        }
        _metas.add(new DataSourceCfgMeta(_name, _connectionUrl, _userName, _password, _params));
    }
    //
    MongoDB.initialize(new IMongoConfig() {

        public boolean isShowLog() {
            return _showLog;
        }

        public String[] getRepositoryPackages() {
            return StringUtils.split(moduleCfgs.get("base.repository_packages"), "|");
        }

        public String getDefaultDataSourceName() {
            return moduleCfgs.get("base.datasource_default");
        }

        public Set<DataSourceCfgMeta> getDataSourceCfgMetas() {
            return _metas;
        }

        public String getCollectionPrefix() {
            return moduleCfgs.get("base.collection_prefix");
        }
    });
}

From source file:net.ymate.platform.module.WebMvcModule.java

@SuppressWarnings("unchecked")
public void initialize(Map<String, String> moduleCfgs) throws Exception {
    IWebEventHandler _eventHandler = ClassUtils.impl(moduleCfgs.get("base.event_handler_class"),
            IWebEventHandler.class, WebMvcModule.class);
    IPluginExtraParser _extraParser = ClassUtils.impl(moduleCfgs.get("base.plugin_extra_parser_class"),
            IPluginExtraParser.class, WebMvcModule.class);
    IWebErrorHandler _errorHandler = ClassUtils.impl(moduleCfgs.get("base.error_handler_class"),
            IWebErrorHandler.class, WebMvcModule.class);
    IWebMultipartHandler _multipartHandler = ClassUtils.impl(moduleCfgs.get("base.multipart_handler_class"),
            IWebMultipartHandler.class, WebMvcModule.class);
    ////from  w  w  w  . j  av  a 2s .com
    Locale _locale = MVC.localeFromStr(moduleCfgs.get("base.locale"), null);
    boolean _i18n = new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.i18n"), "false"))
            .toBooleanValue();
    String _charsetEncoding = StringUtils.defaultIfEmpty(moduleCfgs.get("base.charset_encoding"), "UTF-8");
    //
    List<Class<IFilter>> _extraFilters = new ArrayList<Class<IFilter>>();
    for (String _extraFilter : StringUtils.split(StringUtils.trimToEmpty(moduleCfgs.get("base.extra_filters")),
            "|")) {
        Class<?> _filterClass = ResourceUtils.loadClass(_extraFilter, WebMvcModule.class);
        if (_filterClass != null && ClassUtils.isInterfaceOf(_filterClass, IFilter.class)) {
            _extraFilters.add((Class<IFilter>) _filterClass);
        }
    }
    //
    Map<String, String> _extendParams = new HashMap<String, String>();
    for (String _cfgKey : moduleCfgs.keySet()) {
        if (_cfgKey.startsWith("params")) {
            _extendParams.put(StringUtils.substring(_cfgKey, 7), moduleCfgs.get(_cfgKey));
        }
    }
    //
    String _pluginHome = moduleCfgs.get("base.plugin_home");
    if (StringUtils.isNotBlank(_pluginHome)) {
        if (_pluginHome.startsWith("/WEB-INF/")) {
            File _pluginHomeFile = new File(RuntimeUtils.getRootPath(),
                    StringUtils.substringAfter(_pluginHome, "/WEB-INF/"));
            if (_pluginHomeFile.exists() && _pluginHomeFile.isDirectory()) {
                _pluginHome = _pluginHomeFile.getPath();
            }
        } else if (_pluginHome.contains("${user.dir}")) {
            _pluginHome = doParseVariableUserDir(_pluginHome);
        }
    }
    //
    WebMvcConfig _config = new WebMvcConfig(_eventHandler, _extraParser, _errorHandler, _locale, _i18n,
            _charsetEncoding, _pluginHome, _extendParams,
            StringUtils.split(moduleCfgs.get("base.controller_packages"), '|'));
    //
    _config.setMultipartHandlerClassImpl(_multipartHandler);
    _config.setRestfulModel(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.restful_model"), "false"))
                    .toBooleanValue());
    _config.setConventionModel(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.convention_model"), "true"))
                    .toBooleanValue());
    _config.setConventionUrlrewrite(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.convention_urlrewrite"), "false"))
                    .toBooleanValue());
    _config.setUrlSuffix(StringUtils.defaultIfEmpty(moduleCfgs.get("base.url_suffix"), ""));
    _config.setViewPath(StringUtils.defaultIfEmpty(moduleCfgs.get("base.view_path"), ""));
    _config.setExtraFilters(_extraFilters);
    _config.setUploadTempDir(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.temp_dir"),
            System.getProperty("java.io.tmpdir")));
    _config.setUploadFileSizeMax(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.file_size_max"), "-1"))
                    .toIntValue());
    _config.setUploadTotalSizeMax(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.total_size_max"), "-1"))
                    .toIntValue());
    _config.setUploadSizeThreshold(
            new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.size_threshold"), "10240"))
                    .toIntValue());
    //
    _config.setCookiePrefix(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.prefix"), ""));
    _config.setCookieDomain(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.domain"), ""));
    _config.setCookiePath(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.path"), "/"));
    _config.setCookieAuthKey(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.auth_key"), ""));
    //
    WebMVC.initialize(_config);
}

From source file:net.ymate.platform.mvc.web.context.impl.WebRequestContext.java

/**
 * //from  w w w .ja v  a  2s.  c om
 * @param request 
 * @param prefix URL?
 */
public WebRequestContext(HttpServletRequest request, String prefix) {
    this.prefix = prefix;
    this.url = StringUtils.defaultIfEmpty(request.getPathInfo(), request.getServletPath());
    this.requestMapping = this.url;
    int _pos = 0;
    if (StringUtils.isNotBlank(prefix)) {
        this.requestMapping = StringUtils.substringAfter(this.requestMapping, this.prefix);
    }
    if (!this.requestMapping.endsWith("/")) {
        _pos = this.requestMapping.lastIndexOf('.');
        if (_pos < this.requestMapping.lastIndexOf('/')) {
            _pos = -1;
        }
    } else {
        // (:'/'?'/'?)
        this.requestMapping = this.requestMapping.substring(0, this.requestMapping.length() - 1);
    }
    if (_pos > 0) {
        this.suffix = this.requestMapping.substring(_pos + 1);
        this.requestMapping = this.requestMapping.substring(0, _pos);
    } else {
        this.suffix = "";
    }
}