List of usage examples for org.apache.commons.lang StringUtils uncapitalize
public static String uncapitalize(String str)
Uncapitalizes a String changing the first letter to title case as per Character#toLowerCase(char) .
From source file:com.sinosoft.one.mvc.web.impl.module.ModulesBuilderImpl.java
private List<InterceptorDelegate> findInterceptors(XmlWebApplicationContext context) throws FileNotFoundException, ParserConfigurationException, SAXException, IOException { String[] interceptorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ControllerInterceptor.class); ArrayList<InterceptorDelegate> interceptors = new ArrayList<InterceptorDelegate>(interceptorNames.length); for (String beanName : interceptorNames) { ControllerInterceptor interceptor = (ControllerInterceptor) context.getBean(beanName); Class<?> userClass = ClassUtils.getUserClass(interceptor); if (userClass.isAnnotationPresent(Ignored.class)) { if (logger.isDebugEnabled()) { logger.debug("Ignored interceptor (Ignored):" + interceptor); }/*from w w w. j a v a 2s . c o m*/ continue; } if (userClass.isAnnotationPresent(NotForSubModules.class) && !context.getBeanFactory().containsBeanDefinition(beanName)) { if (logger.isDebugEnabled()) { logger.debug("Ignored interceptor (NotForSubModules):" + interceptor); } continue; } if (!userClass.getSimpleName().endsWith(MvcConstants.INTERCEPTOR_SUFFIX)) { logger.error("", new IllegalArgumentException("Interceptor must be end with '" + MvcConstants.INTERCEPTOR_SUFFIX + "': " + userClass.getName())); continue; } InterceptorBuilder builder = new InterceptorBuilder(interceptor); Interceptor annotation = userClass.getAnnotation(Interceptor.class); if (annotation != null) { builder.oncePerRequest(annotation.oncePerRequest()); } String interceporName; if (beanName.startsWith(AUTO_BEAN_NAME_PREFIX)) { interceporName = StringUtils.removeEnd(StringUtils.uncapitalize(userClass.getSimpleName()), MvcConstants.INTERCEPTOR_SUFFIX); } else { interceporName = StringUtils.removeEnd(beanName, MvcConstants.INTERCEPTOR_SUFFIX); } final String mvc = "mvc"; if (interceporName.startsWith(mvc) && (interceporName.length() == mvc.length() || Character.isUpperCase(interceporName.charAt(mvc.length()))) && !userClass.getName().startsWith("com.sinosoft.one.mvc.")) { throw new IllegalArgumentException("illegal interceptor name '" + interceporName + "' for " + userClass.getName() + ": don't starts with 'mvc', it's reserved"); } builder.name(interceporName); InterceptorDelegate wrapper = builder.build(); interceptors.add(wrapper); if (logger.isDebugEnabled()) { int priority = 0; if (interceptor instanceof Ordered) { priority = ((Ordered) interceptor).getPriority(); } logger.debug("recognized interceptor[priority=" + priority + "]: " // \r\n + wrapper.getName() + "=" + userClass.getName()); } } // start by kylin List<String> rList = ResourceLoaderUtil.getResource("interceptors-order.xml", true); if (rList != null) { Collections.sort(interceptors); int tempGlobalPriority = 1; for (String configInterName : rList) { for (int j = 0, length = interceptors.size(); j < length; j++) { InterceptorDelegate interceptorDelegate = interceptors.get(j); ControllerInterceptor temp = InterceptorDelegate .getMostInnerInterceptor(interceptorDelegate.getInterceptor()); if (temp.getClass().getName().startsWith("com.sinosoft.one.mvc.web") || temp.getClass().getName().startsWith("com.sinosoft.one.mvc.controllers")) { continue; } if (rList.toString().contains(temp.getClass().getName())) { if (configInterName.trim().equals(temp.getClass().getName())) { if (temp instanceof ControllerInterceptorAdapter) { ((ControllerInterceptorAdapter) temp).setPriority( this.GLOBAL_INTERCEPTOR_CONFIG_START_PRIORITY - tempGlobalPriority++); continue; } else { if (temp instanceof ControllerInterceptorAdapter) { ((ControllerInterceptorAdapter) temp).setPriority( this.INTERCEPTOR_NOT_CONFIG_START_PRIORITY - tempGlobalPriority++); } } } } else { if (temp instanceof ControllerInterceptorAdapter) { ((ControllerInterceptorAdapter) temp) .setPriority(this.INTERCEPTOR_NOT_CONFIG_START_PRIORITY - tempGlobalPriority++); } } if (logger.isDebugEnabled()) { logger.debug("Interceptor's Priority:" + temp.getClass().getName() + ":" + ((ControllerInterceptorAdapter) temp).getPriority()); } } } } // end by kylin Collections.sort(interceptors); throwExceptionIfDuplicatedNames(interceptors); return interceptors; }
From source file:mrcg.MRCGInstance.java
private JavaField addReferenceProperty(String fieldName, JavaClass jclass, JavaClass refClass, String[] parts) { JavaField jfield = null;//from w w w . jav a 2 s. c o m if (refClass.isEnum()) { fieldName = StringUtils.capitalize(fieldName); jfield = new JavaField(refClass.getJavaType(), StringUtils.uncapitalize(fieldName) + "Code"); if (new HashSet<String>(Arrays.asList(parts)).contains("nocode")) { jfield = new JavaField(refClass.getJavaType(), StringUtils.uncapitalize(fieldName)); } jfield.setDbType(DBType.Varchar); jfield.setMaxLength(((JavaEnum) refClass).getMaxCodeLength()); } else { fieldName = StringUtils.capitalize(fieldName); // refClass.getName() jfield = new JavaField(JavaType.LONG, StringUtils.uncapitalize(fieldName) + "Id"); jfield.setDbType(DBType.Long); jfield.setRequired(true); // refClass.getName() String field2name = StringUtils.uncapitalize(fieldName); JavaField jfield2 = new JavaField(refClass.getJavaType(), field2name); jfield2.setAutoHandledField(true); jfield2.setDatabaseField(false); jclass.addField(jfield2); // jclass.getReferencedObject() jclass.addImport(JavaType.LOGIC_FACADE); JavaMethod jmethod = new JavaMethod(refClass.getJavaType(), "get" + fieldName); jmethod.setBody("\t\t" + field2name + " = (" + field2name + " == null)?" + JavaType.LOGIC_FACADE.getJustClassName() + ".get(" + refClass.getName() + ".class, " + jfield.getName() + "):" + field2name + ";\n\t\treturn " + field2name + ";"); jclass.addMethod(jmethod); // if 'unique' add singular, else plural // refClass.getRefererObjects() String name = jclass.getName(); // if (fieldName != null) { // name = fieldName; // } // String name = (fieldName == null)?jclass.getName():fieldName; if (isReverseReferenceEnabled(refClass.getName())) { refClass.addImport(JavaType.LOGIC_FACADE); JavaType jtl = new JavaType("java.util.List"); jtl.addType(jclass.getJavaType()); jmethod = new JavaMethod(jtl, "get" + Utils.pluralize(name)); jmethod.setBody( "\t\treturn " + JavaType.LOGIC_FACADE.getJustClassName() + ".list(" + jclass.getName() + ".class, \"" + Utils.toDatabaseFormat(refClass.getName()) + "_id\", getId());"); refClass.addMethod(jmethod); } } jfield.setReferences(refClass); Utils.createBeanProperty(jclass, jfield, true); return jfield; }
From source file:net.ymate.platform.persistence.jdbc.scaffold.EntityGenerator.java
/** * ??//from w w w . j a v a 2 s .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.persistence.jdbc.scaffold.JdbcScaffold.java
/** * ??/*from w w w . j a v a2 s .c o m*/ */ public void createEntityClassFiles() { Map<String, Object> _propMap = buildPropMap(); // boolean _isUseBaseModel = new BlurObject( JDBC_SCAFFOLD_CONF.getProperty("ymp.scaffold.jdbc.use_base_model", "false")).toBooleanValue(); _propMap.put("isUseBaseModel", _isUseBaseModel); _propMap.put("isUseClassSuffix", __isUseClassSuffix); if (_isUseBaseModel) { buildTargetFile("/model/BaseModel.java", "/tmpl/base-model.ftl", _propMap); } // List<String> _tableList = Arrays .asList(StringUtils.split(JDBC_SCAFFOLD_CONF.getProperty("ymp.scaffold.jdbc.table_gen_list"), "|")); if (_tableList == null || _tableList.isEmpty()) { _tableList = getTableNames(); } // String _dbName = JDBC_SCAFFOLD_CONF.getProperty("ymp.scaffold.jdbc.db_name"); String _dbUser = JDBC_SCAFFOLD_CONF.getProperty("ymp.scaffold.jdbc.db_username"); String[] _prefixs = StringUtils.split(JDBC_SCAFFOLD_CONF.getProperty("ymp.scaffold.jdbc.table_prefix"), '|'); boolean _isRemovePrefix = new BlurObject( JDBC_SCAFFOLD_CONF.getProperty("ymp.scaffold.jdbc.remove_table_prefix")).toBooleanValue(); List<String> _tableExcludeList = Arrays.asList(StringUtils.split( JDBC_SCAFFOLD_CONF.getProperty("ymp.scaffold.jdbc.table_exclude_list", "").toLowerCase(), "|")); for (String _tableName : _tableList) { // ??? if (!_tableExcludeList.isEmpty() && _tableExcludeList.contains(_tableName.toLowerCase())) { 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 = JdbcEntityMeta.buildFieldNameToClassAttribute(_tableName); break; } } if (StringUtils.isBlank(_modelName)) { _modelName = JdbcEntityMeta.buildFieldNameToClassAttribute(_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, 0, null); _fieldList.add(_pkAttr); _fieldListForNotNullable.add(_pkAttr); // for (String pkey : _tableMeta.getPkSet()) { ColumnInfo _ci = _tableMeta.getFieldMap().get(pkey); _primaryKeyList.add(new Attr(_ci.getColumnType(), StringUtils.uncapitalize( JdbcEntityMeta.buildFieldNameToClassAttribute(pkey.toLowerCase())), pkey, _ci.isAutoIncrement(), _ci.getNullable(), _ci.getDefaultValue())); _allFieldList.add(new Attr("String", _ci.getColumnName().toUpperCase(), _ci.getColumnName(), false, 0, _ci.getDefaultValue())); } for (String key : _tableMeta.getFieldMap().keySet()) { if (_tableMeta.getPkSet().contains(key)) { continue; } ColumnInfo _ci = _tableMeta.getFieldMap().get(key); Attr _attr = new Attr(_ci.getColumnType(), StringUtils.uncapitalize( JdbcEntityMeta.buildFieldNameToClassAttribute(key.toLowerCase())), key, _ci.isAutoIncrement(), _ci.getNullable(), _ci.getDefaultValue()); _fieldList.add(_attr); _fieldListForNotNullable.add(_attr); _allFieldList.add(new Attr("String", _ci.getColumnName().toUpperCase(), _ci.getColumnName(), _ci.isAutoIncrement(), _ci.getNullable(), _ci.getDefaultValue())); } } else { _propMap.put("primaryKeyType", _tableMeta.getFieldMap().get(_tableMeta.getPkSet().get(0)).getColumnType()); _propMap.put("primaryKeyName", StringUtils.uncapitalize( JdbcEntityMeta.buildFieldNameToClassAttribute(_tableMeta.getPkSet().get(0)))); for (String key : _tableMeta.getFieldMap().keySet()) { ColumnInfo _ci = _tableMeta.getFieldMap().get(key); Attr _attr = new Attr(_ci.getColumnType(), StringUtils.uncapitalize( JdbcEntityMeta.buildFieldNameToClassAttribute(key.toLowerCase())), key, _ci.isAutoIncrement(), _ci.getNullable(), _ci.getDefaultValue()); _fieldList.add(_attr); if (_attr.getNullable() == 0) { _fieldListForNotNullable.add(_attr); } _allFieldList.add(new Attr("String", _ci.getColumnName().toUpperCase(), _ci.getColumnName(), _ci.isAutoIncrement(), _ci.getNullable(), _ci.getDefaultValue())); } } _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"), "/tmpl/model-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(new Attr(_ci.getColumnType(), StringUtils.uncapitalize( JdbcEntityMeta.buildFieldNameToClassAttribute(pkey.toLowerCase())), pkey, _ci.isAutoIncrement(), _ci.getNullable(), _ci.getDefaultValue())); } } buildTargetFile("/model/" + _modelName + "PK.java", "/tmpl/model-pk.ftl", _propMap); } } } }
From source file:ninja.text.TextImpl.java
@Override public Text uncapitalize() { return Text.of(StringUtils.uncapitalize(data.toString())); }
From source file:nl.strohalm.cyclos.utils.access.PermissionHelper.java
private static String process(final String string) { return StringUtils.uncapitalize(WordUtils.capitalizeFully(string, NAME_DELIMITERS).replaceAll("\\_", "")); }
From source file:nl.strohalm.cyclos.utils.SpringHelper.java
/** * Retrieves a bean from the factory, casting it *//*from ww w.j a v a2s . c o m*/ @SuppressWarnings("unchecked") public static <T> T bean(final BeanFactory beanFactory, final Class<T> requiredType) { T bean; if (Service.class.isAssignableFrom(requiredType)) { // in the case of a service there are two implementations (local & security) for each security service type // then we must retrieve the bean from the context using its id. bean = (T) beanFactory.getBean(StringUtils.uncapitalize(requiredType.getSimpleName())); } else { bean = beanFactory.getBean(requiredType); } ensureSecurityService(bean, null); return bean; }
From source file:org.andromda.cartridges.gui.metafacades.GuiManageableEntityLogicImpl.java
/** * @return StringUtils.uncapitalize(this.getName()) + "Controller" * @see org.andromda.cartridges.gui.metafacades.GuiManageableEntity#getControllerBeanName() */// w w w . j av a 2s. co m @Override protected String handleGetControllerBeanName() { return StringUtils.uncapitalize(this.getName()) + "Controller"; }
From source file:org.apache.cayenne.dbsync.merge.builders.DefaultBuilder.java
public String getRandomJavaName() { int count = dataFactory.getNumberBetween(1, 5); StringBuilder res = new StringBuilder(); for (int i = 0; i < count; i++) { res.append(StringUtils.capitalize(dataFactory.getRandomWord())); }// w ww . ja va 2 s . c om return StringUtils.uncapitalize(res.toString()); }
From source file:org.apache.cayenne.migration.MigrationGenerator.java
protected String tableName(DbEntity entity) { return StringUtils.uncapitalize(entity.getName()); }