List of usage examples for org.apache.commons.lang StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(String str, String prefix)
Case insensitive check if a String starts with a specified prefix.
From source file:net.sourceforge.squirrel_sql.plugins.sqlscript.table_script.AbstractDataScriptCommand.java
/** * Looks for the current selected SQL statement in the editor pane. * This ensures, that the selected statement is realy a SELECT statement. * These errors can occurs,//from ww w . jav a 2s . c om * <li>no query selected</li> * <li>more than one query selected</li> * <li>not a SELECT statement selected</li> * In all these cases, the user will get a message and <code>null</code> will be returned. * @return the selected SELECT statement or null, if not exactly one SELECT statement is selected. */ protected String getSelectedSelectStatement() { ISQLPanelAPI api = FrameWorkAcessor.getSQLPanelAPI(getSession(), getPlugin()); String script = api.getSQLScriptToBeExecuted(); IQueryTokenizer qt = getSession().getQueryTokenizer(); qt.setScriptToTokenize(script); if (false == qt.hasQuery()) { // i18n[CreateFileOfCurrentSQLCommand.noQuery=No query found to // create the script from.] getSession().showErrorMessage(s_stringMgr.getString("AbstractDataScriptCommand.noQuery")); return null; } if (qt.getQueryCount() > 1) { // i18n[CreateFileOfCurrentSQLCommand.moreThanOnQuery=There are more than one query selected. Only the first statement will be used.] getSession().showWarningMessage(s_stringMgr.getString("AbstractDataScriptCommand.moreThanOnQuery")); } String currentSQL = qt.nextQuery(); if (StringUtils.startsWithIgnoreCase(currentSQL, "select") == false) { // i18n[CreateFileOfCurrentSQLCommand.notASelect=The selected SQL is not a SELECT statement.] getSession().showErrorMessage(s_stringMgr.getString("AbstractDataScriptCommand.notASelect")); return null; } return currentSQL; }
From source file:net.triptech.metahive.web.PersonController.java
@ModelAttribute("userroles") public Collection<UserRole> populateUserRoles() { Collection<UserRole> userRoles = new ArrayList<UserRole>(); for (UserRole userRole : UserRole.values()) { if (StringUtils.startsWithIgnoreCase(userRole.name(), "ROLE")) { userRoles.add(userRole);/* w w w . j a v a 2s .c om*/ } } return userRoles; }
From source file:net.ymate.framework.core.util.WebUtils.java
public static String buildRedirectURL(InterceptContext context, String redirectUrl, boolean needPrefix) { String _redirectUrl = StringUtils.trimToNull(redirectUrl); if (_redirectUrl == null) { _redirectUrl = StringUtils.defaultIfBlank(WebContext.getRequest().getParameter(Optional.REDIRECT_URL), context != null ? context.getContextParams().get(Optional.REDIRECT_URL) : ""); if (StringUtils.isBlank(_redirectUrl)) { _redirectUrl = WebContext.getContext().getOwner().getOwner().getConfig() .getParam(Optional.REDIRECT_HOME_URL); if (StringUtils.isBlank(_redirectUrl)) { _redirectUrl = StringUtils.defaultIfBlank(_redirectUrl, WebUtils.baseURL(WebContext.getRequest())); }/* www.j a v a2 s. c o m*/ } } if (needPrefix && !StringUtils.startsWithIgnoreCase(_redirectUrl, "http://") && !StringUtils.startsWithIgnoreCase(_redirectUrl, "https://")) { _redirectUrl = WebUtils.buildURL(WebContext.getRequest(), _redirectUrl, true); } return _redirectUrl; }
From source file:net.ymate.framework.core.util.WebUtils.java
public static String buildRedirectCustomURL(InterceptContext context, String defaultValue) { String _returnValue = null;/*from w ww . j a va 2 s.c o m*/ if (context.getContextParams().containsKey(Optional.CUSTOM_REDIRECT)) { String _value = context.getContextParams().get(Optional.CUSTOM_REDIRECT); if (StringUtils.equalsIgnoreCase(_value, Optional.CUSTOM_REDIRECT)) { _value = Optional.REDIRECT_CUSTOM_URL; } else if (StringUtils.startsWithIgnoreCase(_value, "http://") || StringUtils.startsWithIgnoreCase(_value, "https://")) { return _value; } if (StringUtils.isNotBlank(_value)) { _returnValue = context.getOwner().getConfig().getParam(_value); } } return StringUtils.trimToEmpty(StringUtils.defaultIfBlank(_returnValue, defaultValue)); }
From source file:net.ymate.module.oauth.base.OAuthClientBean.java
public boolean checkDomain(String redirectURI) { if (StringUtils.isBlank(domain)) { return true; }/* w w w .ja v a 2 s . c o m*/ boolean _resultValue; try { _resultValue = StringUtils.equalsIgnoreCase(new URL(domain).getHost(), new URL(redirectURI).getHost()); } catch (MalformedURLException e) { _resultValue = StringUtils.startsWithIgnoreCase(redirectURI, domain); } return _resultValue; }
From source file:net.ymate.module.sso.impl.DefaultSSOModuleCfg.java
public DefaultSSOModuleCfg(YMP owner) { IConfigReader _moduleCfg = MapSafeConfigReader.bind(owner.getConfig().getModuleConfigs(ISSO.MODULE_NAME)); ///*from ww w.j a v a2 s . c o m*/ __tokenCookieName = _moduleCfg.getString(TOKEN_COOKIE_NAME, ISSO.MODULE_NAME + "_token"); // __tokenHeaderName = _moduleCfg.getString(TOKEN_HEADER_NAME, "X-ModuleSSO-Token"); // __tokenParamName = _moduleCfg.getString(TOKEN_PARAM_NAME, "token"); // __tokenMaxage = _moduleCfg.getInt(TOKEN_MAXAGE); // __tokenValidateTimeInterval = _moduleCfg.getInt(TOKEN_VALIDATE_TIME_INTERVAL); // __cacheNamePrefix = _moduleCfg.getString(CACHE_NAME_PREFIX); // __multiSessionEnabled = _moduleCfg.getBoolean(MULTI_SESSION_ENABLED); // __ipCheckEnabled = _moduleCfg.getBoolean(IP_CHECK_ENABLED); // __isClientMode = _moduleCfg.getBoolean(CLIENT_MODE); // __serviceAuthKey = _moduleCfg.getString(SERVICE_AUTH_KEY); // if (__isClientMode) { __serviceBaseUrl = StringUtils.trimToNull(_moduleCfg.getString(SERVICE_BASE_URL)); if (__serviceBaseUrl != null) { if (!StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "http://") && !StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "https://")) { throw new IllegalArgumentException("The parameter " + SERVICE_BASE_URL + " is invalid"); } else if (!StringUtils.endsWith(__serviceBaseUrl, "/")) { __serviceBaseUrl = __serviceBaseUrl + "/"; } } } // __tokenAdapter = _moduleCfg.getClassImpl(TOKEN_ADAPTER_CLASS, ISSOTokenAdapter.class); if (__tokenAdapter == null) { __tokenAdapter = new DefaultSSOTokenAdapter(); } // __tokenStorageAdapter = _moduleCfg.getClassImpl(STORAGE_ADAPTER_CLASS, ISSOTokenStorageAdapter.class); if (!__isClientMode && __tokenStorageAdapter == null) { throw new IllegalArgumentException("The parameter " + STORAGE_ADAPTER_CLASS + " is invalid"); } // if (!__isClientMode) { __tokenAttributeAdapter = _moduleCfg.getClassImpl(ATTRIBUTE_ADAPTER_CLASS, ISSOTokenAttributeAdapter.class); } }
From source file:net.ymate.module.webproxy.impl.DefaultModuleCfg.java
public DefaultModuleCfg(YMP owner) { Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IWebProxy.MODULE_NAME); ///*from ww w . j av a 2s.com*/ __serviceBaseUrl = _moduleCfgs.get("service_base_url"); if (StringUtils.isBlank(__serviceBaseUrl)) { throw new NullArgumentException("service_base_url"); } if (!StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "http://") && !StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "https://")) { throw new IllegalArgumentException("Argument service_base_url must be start with http or https"); } else if (StringUtils.endsWith(__serviceBaseUrl, "/")) { __serviceBaseUrl = StringUtils.substringBeforeLast(__serviceBaseUrl, "/"); } // __serviceRequestPrefix = StringUtils.trimToEmpty(_moduleCfgs.get("service_request_prefix")); if (StringUtils.isNotBlank(__serviceRequestPrefix) && !StringUtils.startsWith(__serviceRequestPrefix, "/")) { __serviceRequestPrefix = "/" + __serviceRequestPrefix; } // __useProxy = BlurObject.bind(_moduleCfgs.get("use_proxy")).toBooleanValue(); if (__useProxy) { Proxy.Type _proxyType = Proxy.Type .valueOf(StringUtils.defaultIfBlank(_moduleCfgs.get("proxy_type"), "HTTP").toUpperCase()); int _proxyPrort = BlurObject.bind(StringUtils.defaultIfBlank(_moduleCfgs.get("proxy_port"), "80")) .toIntValue(); String _proxyHost = _moduleCfgs.get("proxy_host"); if (StringUtils.isBlank(_proxyHost)) { throw new NullArgumentException("proxy_host"); } __proxy = new Proxy(_proxyType, new InetSocketAddress(_proxyHost, _proxyPrort)); } // __useCaches = BlurObject.bind(_moduleCfgs.get("use_caches")).toBooleanValue(); __instanceFollowRedirects = BlurObject.bind(_moduleCfgs.get("instance_follow_redirects")).toBooleanValue(); // __connectTimeout = BlurObject.bind(_moduleCfgs.get("connect_timeout")).toIntValue(); __readTimeout = BlurObject.bind(_moduleCfgs.get("read_timeout")).toIntValue(); // __transferBlackList = Arrays .asList(StringUtils.split(StringUtils.trimToEmpty(_moduleCfgs.get("transfer_blacklist")), "|")); // __transferHeaderEnabled = BlurObject.bind(_moduleCfgs.get("transfer_header_enabled")).toBooleanValue(); // if (__transferHeaderEnabled) { String[] _filters = StringUtils .split(StringUtils.lowerCase(_moduleCfgs.get("transfer_header_whitelist")), "|"); if (_filters != null && _filters.length > 0) { __transferHeaderWhiteList = Arrays.asList(_filters); } else { __transferHeaderWhiteList = Collections.emptyList(); } // _filters = StringUtils.split(StringUtils.lowerCase(_moduleCfgs.get("transfer_header_blacklist")), "|"); if (_filters != null && _filters.length > 0) { __transferHeaderBlackList = Arrays.asList(_filters); } else { __transferHeaderBlackList = Collections.emptyList(); } // _filters = StringUtils.split(StringUtils.lowerCase(_moduleCfgs.get("response_header_whitelist")), "|"); if (_filters != null && _filters.length > 0) { __responseHeaderWhiteList = Arrays.asList(_filters); } else { __responseHeaderWhiteList = Collections.emptyList(); } } else { __transferHeaderWhiteList = Collections.emptyList(); __transferHeaderBlackList = Collections.emptyList(); // __responseHeaderWhiteList = Collections.emptyList(); } }
From source file:net.ymate.platform.mvc.web.support.RequestMappingParser.java
/** * @param context // ww w . ja v a 2 s. c o m * @param mappingSet ???'$'? * @return ?????????WebContextPathVariable? */ public String doParser(IRequestContext context, Set<String> mappingSet) { String _requestMapping = this.fixMappingPart(context.getRequestMapping()); // ??PairObject<Mapping[??], ??> Set<PairObject<String[], Integer>> _filteredMapping = new HashSet<PairObject<String[], Integer>>(); for (String _key : mappingSet) { if (_key.contains("{")) { String _mappingKey = StringUtils.substringBefore(_key, "{"); String _fixedMappingKey = this.fixMappingPart(_mappingKey); if (StringUtils.startsWithIgnoreCase(_requestMapping, _fixedMappingKey)) { // ????? String _paramKey = _key.substring(_key.indexOf("{")); _filteredMapping.add(new PairObject<String[], Integer>( new String[] { _key, _mappingKey, _fixedMappingKey, _paramKey }, StringUtils.split(_paramKey, "/").length)); } } } // ????? PairObject<String[], Integer> _result = null; String _mappingParamPart = null; for (PairObject<String[], Integer> _item : _filteredMapping) { // ????? _mappingParamPart = StringUtils.substringAfter(_requestMapping, _item.getKey()[2]); // ??? int _paramPartCount = StringUtils.split(_mappingParamPart, "/").length; // ????? if (_paramPartCount == _item.getValue()) { _result = _item; break; } } if (_result != null) { Map<String, String> _params = this.parserMappingParams(_mappingParamPart, _result.getKey()[3]); if (WebContext.getContext() != null) { // ???WebContextPathVariable? for (String _key : _params.keySet()) { WebContext.getContext().put(_key, _params.get(_key)); } } return _result.getKey()[0]; } return null; }
From source file:net.ymate.platform.persistence.jdbc.scaffold.EntityGenerator.java
/** * ??//w ww. j a v a 2s . c om */ public void createEntityClassFiles() { Map<String, Object> _propMap = buildPropMap(); // boolean _isUseBaseEntity = BlurObject.bind(__owner.getConfig().getParam("jdbc.use_base_entity")) .toBooleanValue(); boolean _isUseClassSuffix = BlurObject.bind(__owner.getConfig().getParam("jdbc.use_class_suffix")) .toBooleanValue(); boolean _isUseChainMode = BlurObject.bind(__owner.getConfig().getParam("jdbc.use_chain_mode")) .toBooleanValue(); boolean _isUseStateSupport = BlurObject.bind(__owner.getConfig().getParam("jdbc.use_state_support")) .toBooleanValue(); _propMap.put("isUseBaseEntity", _isUseBaseEntity); _propMap.put("isUseClassSuffix", _isUseClassSuffix); _propMap.put("isUseChainMode", _isUseChainMode); _propMap.put("isUseStateSupport", _isUseStateSupport); if (_isUseBaseEntity) { buildTargetFile("/model/BaseEntity.java", "/BaseEntity.ftl", _propMap); } // List<String> _tableList = Arrays.asList(StringUtils .split(StringUtils.defaultIfBlank(__owner.getConfig().getParam("jdbc.table_list"), ""), "|")); if (_tableList.isEmpty()) { _tableList = getTableNames(); } // String _dbName = __owner.getConfig().getParam("jdbc.db_name"); String _dbUser = __owner.getConfig().getParam("jdbc.db_username"); String[] _prefixs = StringUtils .split(StringUtils.defaultIfBlank(__owner.getConfig().getParam("jdbc.table_prefix"), ""), '|'); boolean _isRemovePrefix = new BlurObject(__owner.getConfig().getParam("jdbc.remove_table_prefix")) .toBooleanValue(); List<String> _tableExcludeList = Arrays.asList(StringUtils.split(StringUtils .defaultIfBlank(__owner.getConfig().getParam("jdbc.table_exclude_list"), "").toLowerCase(), "|")); for (String _tableName : _tableList) { // ??? if (!_tableExcludeList.isEmpty()) { if (_tableExcludeList.contains(_tableName.toLowerCase())) { continue; } else { boolean _flag = false; for (String _excludedName : _tableExcludeList) { if (StringUtils.contains(_excludedName, "*") && StringUtils.startsWithIgnoreCase(_tableName, StringUtils.substringBefore(_excludedName, "*"))) { _flag = true; break; } } if (_flag) { continue; } } } TableMeta _tableMeta = getTableMeta(_dbName, _dbUser, _tableName); if (_tableMeta != null) { String _modelName = null; for (String _prefix : _prefixs) { if (_tableName.startsWith(_prefix)) { if (_isRemovePrefix) { _tableName = _tableName.substring(_prefix.length()); } _modelName = StringUtils.capitalize(EntityMeta.propertyNameToFieldName(_tableName)); break; } } if (StringUtils.isBlank(_modelName)) { _modelName = StringUtils.capitalize(EntityMeta.propertyNameToFieldName(_tableName)); } // _propMap.put("tableName", _tableName); _propMap.put("modelName", _modelName); List<Attr> _fieldList = new ArrayList<Attr>(); // List<Attr> _fieldListForNotNullable = new ArrayList<Attr>(); // ? List<Attr> _allFieldList = new ArrayList<Attr>(); // ???? if (_tableMeta.getPkSet().size() > 1) { _propMap.put("primaryKeyType", _modelName + "PK"); _propMap.put("primaryKeyName", StringUtils.uncapitalize((String) _propMap.get("primaryKeyType"))); List<Attr> _primaryKeyList = new ArrayList<Attr>(); _propMap.put("primaryKeyList", _primaryKeyList); Attr _pkAttr = new Attr((String) _propMap.get("primaryKeyType"), (String) _propMap.get("primaryKeyName"), null, false, false, 0, 0, 0, null, null); _fieldList.add(_pkAttr); _fieldListForNotNullable.add(_pkAttr); // for (String pkey : _tableMeta.getPkSet()) { ColumnInfo _ci = _tableMeta.getFieldMap().get(pkey); _primaryKeyList.add(_ci.toAttr()); _allFieldList.add(new Attr("String", _ci.getColumnName().toUpperCase(), _ci.getColumnName(), _ci.isAutoIncrement(), _ci.isSigned(), _ci.getPrecision(), _ci.getScale(), _ci.getNullable(), _ci.getDefaultValue(), _ci.getRemarks())); } for (String key : _tableMeta.getFieldMap().keySet()) { if (_tableMeta.getPkSet().contains(key)) { continue; } ColumnInfo _ci = _tableMeta.getFieldMap().get(key); Attr _attr = _ci.toAttr(); _fieldList.add(_attr); _fieldListForNotNullable.add(_attr); _allFieldList.add(new Attr("String", _ci.getColumnName().toUpperCase(), _ci.getColumnName(), _ci.isAutoIncrement(), _ci.isSigned(), _ci.getPrecision(), _ci.getScale(), _ci.getNullable(), _ci.getDefaultValue(), _ci.getRemarks())); } } else { _propMap.put("primaryKeyType", _tableMeta.getFieldMap().get(_tableMeta.getPkSet().get(0)).getColumnType()); _propMap.put("primaryKeyName", StringUtils .uncapitalize(EntityMeta.propertyNameToFieldName(_tableMeta.getPkSet().get(0)))); for (String key : _tableMeta.getFieldMap().keySet()) { ColumnInfo _ci = _tableMeta.getFieldMap().get(key); Attr _attr = _ci.toAttr(); _fieldList.add(_attr); if (_attr.getNullable() == 0) { _fieldListForNotNullable.add(_attr); } _allFieldList.add(new Attr("String", _ci.getColumnName().toUpperCase(), _ci.getColumnName(), _ci.isAutoIncrement(), _ci.isSigned(), _ci.getPrecision(), _ci.getScale(), _ci.getNullable(), _ci.getDefaultValue(), _ci.getRemarks())); } } _propMap.put("fieldList", _fieldList); // ?????? _propMap.put("notNullableFieldList", _fieldList.size() == _fieldListForNotNullable.size() ? Collections.emptyList() : _fieldListForNotNullable); _propMap.put("allFieldList", _allFieldList); // buildTargetFile("/model/" + _modelName + (_isUseClassSuffix ? "Model.java" : ".java"), "/Entity.ftl", _propMap); // if (_tableMeta.getPkSet().size() > 1) { _propMap.put("modelName", _modelName); if (_tableMeta.getPkSet().size() > 1) { List<Attr> _primaryKeyList = new ArrayList<Attr>(); _propMap.put("primaryKeyList", _primaryKeyList); // for (String pkey : _tableMeta.getPkSet()) { ColumnInfo _ci = _tableMeta.getFieldMap().get(pkey); _primaryKeyList.add(_ci.toAttr()); } } buildTargetFile("/model/" + _modelName + "PK.java", "/EntityPK.ftl", _propMap); } } } }
From source file:net.ymate.platform.webmvc.support.RequestMappingParser.java
/** * @param context /* ww w . j av a2 s .c om*/ * @return ?????????WebContextPathVariable? */ public RequestMeta doParse(IRequestContext context) { RequestMeta _meta = null; Map<String, RequestMeta> _mappingMap = null; switch (context.getHttpMethod()) { case POST: _mappingMap = __MAPPING_META_FOR_POST; break; case DELETE: _mappingMap = __MAPPING_META_FOR_DELETE; break; case PUT: _mappingMap = __MAPPING_META_FOR_PUT; break; case OPTIONS: _mappingMap = __MAPPING_META_FOR_OPTIONS; break; case HEAD: _mappingMap = __MAPPING_META_FOR_HEAD; break; case TRACE: _mappingMap = __MAPPING_META_FOR_TRACE; break; default: _mappingMap = __MAPPING_META_FOR_GET; } _meta = _mappingMap.get(context.getRequestMapping()); if (_meta == null) { String _requestMapping = this.__doFixMappingPart(context.getRequestMapping()); // ??PairObject<Mapping[??], ??> Set<PairObject<String[], Integer>> _filteredMapping = new HashSet<PairObject<String[], Integer>>(); for (String _key : _mappingMap.keySet()) { if (_key.contains("{")) { String _mappingKey = StringUtils.substringBefore(_key, "{"); String _fixedMappingKey = this.__doFixMappingPart(_mappingKey); if (StringUtils.startsWithIgnoreCase(_requestMapping, _fixedMappingKey)) { // ????? String _paramKey = _key.substring(_key.indexOf('{')); _filteredMapping.add(new PairObject<String[], Integer>( new String[] { _key, _mappingKey, _fixedMappingKey, _paramKey }, StringUtils.split(_paramKey, "/").length)); } } } // ????? PairObject<String[], Integer> _result = null; String _mappingParamPart = null; for (PairObject<String[], Integer> _item : _filteredMapping) { // ????? _mappingParamPart = StringUtils.substringAfter(_requestMapping, _item.getKey()[2]); // ??? int _paramPartCount = StringUtils.split(_mappingParamPart, "/").length; // ????? if (_paramPartCount == _item.getValue()) { _result = _item; break; } } if (_result != null) { Map<String, String> _params = this.__doParserMappingParams(_mappingParamPart, _result.getKey()[3]); // ???WebContextPathVariable? for (Map.Entry<String, String> _entry : _params.entrySet()) { context.addAttribute(_entry.getKey(), _entry.getValue()); } _meta = _mappingMap.get(_result.getKey()[0]); } } return _meta; }