private void setJsonTree(List<String> path, JSONArray parent, GadgetSpec gadgetSpec) throws JSONException { String tempId = "root"; // Temp variable to keep track of parent ID. for (int i = 0; i < path.size(); i++) { JSONObject newNode = new JSONObject(); if (!this.isNodeExisting(path.get(i), parent)) { // If node is a GadgetSpec (last in path) if (i == path.size() - 1) { newNode.put("name", StringUtils.capitalize(gadgetSpec.getTitle())); newNode.put("hasChildren", false); newNode.put("isDefault", gadgetSpec.isDefault()); newNode.put("id", gadgetSpec.getId()); } // Id node is a unique folder else { newNode.put("name", StringUtils.capitalize(path.get(i))); newNode.put("hasChildren", true); newNode.put("isDefault", false); newNode.put("id", getFolderId(path.get(i))); } newNode.put("parent", tempId); parent.put(newNode); } tempId = getFolderId(path.get(i)); } }
/** 调用Setter方法, 仅匹配方法名。 支持多级,如:对象名.对象名.方法 */ public static void invokeSetter(Object obj, String propertyName, Object value) { Object object = obj; String[] names = StringUtils.split(propertyName, "."); for (int i = 0; i < names.length; i++) { if (i < names.length - 1) { String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]); object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {}); } else { String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]); invokeMethodByName(object, setterMethodName, new Object[] {value}); } } }
private Class<?> getType(ClassLoader loader, InjectionTarget target) { try { final Class<?> clazz = loader.loadClass(target.getInjectionTargetClass()); try { final Field field = clazz.getDeclaredField(target.getInjectionTargetName()); return field.getType(); } catch (NoSuchFieldException e) { } // TODO Technically we should match by case final String bestName = "set" + StringUtils.capitalize(target.getInjectionTargetName()); final String name = "set" + target.getInjectionTargetName().toLowerCase(); Class<?> found = null; for (Method method : clazz.getDeclaredMethods()) { if (method.getParameterTypes().length == 1) { if (method.getName().equals(bestName)) { return method.getParameterTypes()[0]; } else if (method.getName().toLowerCase().equals(name)) { found = method.getParameterTypes()[0]; } } } if (found != null) { return found; } } catch (Throwable e) { } return Object.class; }
/** * Appends a getter method for the text of html tag which contains the variable specified by the * name into the given string builder. * * @param methodBuilder {@link StringBuilder} the generated method will be appended to * @param uniqueVariableName the unique variable name with a sequential number * @param tagInfo the information of the html tag containing the template variable * @param varInfo the information of the template variable * @param isRepeated the boolean whether the specified html tag appears in a repeated part */ private void appendTextGetter( StringBuilder methodBuilder, String uniqueVariableName, HtmlTagInfo tagInfo, VariableInfo varInfo, boolean isRepeated) { // TODO(kazuu): Help to select proper one from getFoo, getFoo2, getFoo3 ... appendLine(methodBuilder); String methodNamePrefix = !isRepeated ? "String getTextOf" : "List<String> getTextsOf"; String foundedProcess = !isRepeated ? "return matcher.group(3);" : "result.add(matcher.group(3));"; String finalProcess = !isRepeated ? "return null;" : "return result;"; appendLine( methodBuilder, 1, String.format( "public %s%s() {", methodNamePrefix, StringUtils.capitalize(uniqueVariableName))); if (isRepeated) { appendLine(methodBuilder, 2, "List<String> result = new ArrayList<String>();"); } appendLine( methodBuilder, 2, "Matcher matcher = commentPattern.matcher(driver.getPageSource());"); appendLine(methodBuilder, 2, "while (matcher.find()) {"); appendLine( methodBuilder, 3, String.format( "if (matcher.group(1).equals(\"%s\") && matcher.group(2).equals(\"%s\")) {", tagInfo.getAttributeValue(), varInfo.getName())); appendLine(methodBuilder, 4, foundedProcess); appendLine(methodBuilder, 3, "}"); appendLine(methodBuilder, 2, "}"); appendLine(methodBuilder, 2, finalProcess); appendLine(methodBuilder, 1, "}"); }
private String capitalizeAllWords(String dateString) { String newDateString = ""; for (String word : dateString.split(" ")) { newDateString += StringUtils.capitalize(word.toLowerCase()) + " "; } return newDateString.trim(); }
@Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { // Context, XWiki XWikiContext context = getXWikiContext(); XWiki xwiki = context.getWiki(); // Current wiki String currentWikiId = wikiDescriptorManager.getCurrentWikiId(); // Get the old wiki descriptor DocumentReference oldWikiDescriptorReference = new DocumentReference( wikiDescriptorManager.getMainWikiId(), XWiki.SYSTEM_SPACE, String.format("XWikiServer%s", StringUtils.capitalize(currentWikiId))); XWikiDocument oldWikiDescriptor = xwiki.getDocument(oldWikiDescriptorReference, context); // Try to get the old workspace object DocumentReference oldClassDocument = new DocumentReference( wikiDescriptorManager.getMainWikiId(), WORKSPACE_CLASS_SPACE, WORKSPACE_CLASS_PAGE); BaseObject oldObject = oldWikiDescriptor.getXObject(oldClassDocument); // Upgrade depending of the type if (oldObject != null || isWorkspaceTemplate(currentWikiId)) { // It's a workspace upgradeWorkspace(oldObject, currentWikiId, oldWikiDescriptor); } else { // It's a regular subwiki upgradeRegularSubwiki(currentWikiId); } }
/** 调用Getter方法. 支持多级,如:对象名.对象名.方法 */ public static Object invokeGetter(Object obj, String propertyName) { Object object = obj; for (String name : StringUtils.split(propertyName, ".")) { String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name); object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {}); } return object; }
static { Translations en = Translations.getTranslations(Locale.ENGLISH); for (int i = 0; i < 190; i++) { EngineeringUnits eu = new EngineeringUnits(i); ENGINEERING_UNITS_CODES.addElement( i, StringUtils.capitalize(en.translate(eu.getKey())), eu.getKey()); } }
/** * 调用Setter方法. * * @param object * @param propertyName * @param value * @param propertyType 用于查找Setter方法,为空时使用value的Class替代. */ public static void invokeSetterMethod( final Object object, final String propertyName, final Object value, final Class<?> propertyType) { Class<?> type = propertyType != null ? propertyType : value.getClass(); String methodName = "set" + StringUtils.capitalize(propertyName); invokeMethod(object, methodName, new Class<?>[] {type}, new Object[] {value}); }
/** * Returns the accessor name for the given field name and field type. * * @param fieldName the field name used to determine the accessor name * @param fieldType the field type * @return the accessor method name */ public static JavaSymbolName getAccessorMethodName( final JavaSymbolName fieldName, final JavaType fieldType) { Validate.notNull(fieldName, "Field name required"); Validate.notNull(fieldType, "Field type required"); final String capitalizedFieldName = StringUtils.capitalize(fieldName.getSymbolName()); return fieldType.equals(JavaType.BOOLEAN_PRIMITIVE) ? new JavaSymbolName("is" + capitalizedFieldName) : new JavaSymbolName("get" + capitalizedFieldName); }
@SuppressWarnings("unchecked") public static Class<? extends Model> getModelClass(String collectionName) throws ClassNotFoundException { StringBuffer className = new StringBuffer(); for (String name : collectionName.split("_")) { className.append(StringUtils.capitalize(name)); } return (Class<? extends Model>) Class.forName(Model.class.getPackage().getName() + "." + className); }
/** * Gets rule information of IOpenField instance. * * @param field IOpenField instance * @return rule info */ private static RuleInfo getRuleInfoForField(IOpenField field) { String methodName = String.format("get%s", StringUtils.capitalize(field.getName())); Class<?>[] paramTypes = new Class<?>[0]; Class<?> returnType = field.getType().getInstanceClass(); RuleInfo ruleInfo = createRuleInfo(methodName, paramTypes, returnType); return ruleInfo; }
public static Method getNonVoidSetter(Class<?> clazz, String fieldName) { String methodName = "set" + StringUtils.capitalize(fieldName); for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == 1 && method.getReturnType() != Void.TYPE) { return method; } } return null; }
/** * Retrieve the setter for the specified class/field if it exists. * * @param clazz * @param f * @return */ public static Method getSetter(Class<?> clazz, Field f) { Method setter = null; for (Method m : clazz.getMethods()) { if (ReflectionUtils.isSetter(m) && m.getName().equals(SETTER_PREFIX + StringUtils.capitalize(f.getName()))) { setter = m; break; } } return setter; }
@Override public void bindData(View view, BaseType data, int position) { ContactHolder holder = (ContactHolder) getHolder(view); Contact contact = (Contact) data; if (contact.getFirstName() != null) holder.primaryText.setText(StringUtils.capitalize(contact.getFirstName())); else holder.primaryText.setText(StringUtils.capitalize(contact.getName())); String url = contact.getPhoto(); if (url != null && url.length() > 0) { ImageLoader.display(holder.picture, url); holder.letterText.setVisibility(View.GONE); } else { holder.letterText.setText(contact.getInitials()); holder.picture.setImageResource(ContactsUtil.getDrawable(contact.getId())); holder.letterText.setVisibility(View.VISIBLE); } }
static void appendFieldNote( final StringBuilder fieldNoteBuffer, final Geocache cache, final LogEntry log) { fieldNoteBuffer .append(cache.getGeocode()) .append(',') .append(fieldNoteDateFormat.format(new Date(log.date))) .append(',') .append(StringUtils.capitalize(log.type.type)) .append(",\"") .append(StringUtils.replaceChars(log.log, '"', '\'')) .append("\"\n"); }
private Method findGetterMethod(Class<?> classObject, Field field) { String methodName = "get" + StringUtils.capitalize(field.getName()); Method foundMethod = null; for (Method method : classObject.getMethods()) { if (method.getName().equals(methodName)) { foundMethod = method; break; } } return foundMethod; }
static { InputStream inputStream = null; try { inputStream = FileUtils.openInputStream(new File(Database.DICTIONARY)); for (String word : IOUtils.readLines(inputStream, "UTF-8")) { WORDS.add(org.apache.commons.lang3.StringUtils.capitalize(word)); } } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(inputStream); } }
@Test public void extractClassShouldBeSupportString() throws NoSuchFieldException, SecurityException, NoSuchMethodException { final Method method = configModel .getClass() .getDeclaredMethod("get" + StringUtils.capitalize(UtilTest.CONFIG_CLASS_TYPED_FIELD)); assertEquals(method.getReturnType(), Class.class); assertTrue( conf.isSupported( configModel.getClass().getDeclaredField(UtilTest.CONFIG_CLASS_TYPED_FIELD))); }
@Override public Component getListCellRendererComponent( final JList<?> list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { Object item = value; if (item != null) { item = StringUtils.capitalize(value.toString().toLowerCase()); } return super.getListCellRendererComponent(list, item, index, isSelected, cellHasFocus); }
/** {@inheritDoc} */ public void apply(HSSFCell cell, HSSFCellStyle cellStyle, Map<String, String> style) { for (String pos : new String[] {TOP, RIGHT, BOTTOM, LEFT}) { String posName = StringUtils.capitalize(pos.toLowerCase()); // color String colorAttr = BORDER + "-" + pos + "-" + COLOR; HSSFColor poiColor = CssUtils.parseColor(cell.getSheet().getWorkbook(), style.get(colorAttr)); if (poiColor != null) { try { MethodUtils.invokeMethod(cellStyle, "set" + posName + "BorderColor", poiColor.getIndex()); } catch (Exception e) { log.error("Set Border Color Error Caused.", e); } } // width int width = CssUtils.getInt(style.get(BORDER + "-" + pos + "-" + WIDTH)); String styleAttr = BORDER + "-" + pos + "-" + STYLE; String styleValue = style.get(styleAttr); short shortValue = -1; // empty or solid if (StringUtils.isBlank(styleValue) || "solid".equals(styleValue)) { if (width > 2) { shortValue = CellStyle.BORDER_THICK; } else if (width > 1) { shortValue = CellStyle.BORDER_MEDIUM; } else { shortValue = CellStyle.BORDER_THIN; } } else if (ArrayUtils.contains(new String[] {NONE, HIDDEN}, styleValue)) { shortValue = CellStyle.BORDER_NONE; } else if (DOUBLE.equals(styleValue)) { shortValue = CellStyle.BORDER_DOUBLE; } else if (DOTTED.equals(styleValue)) { shortValue = CellStyle.BORDER_DOTTED; } else if (DASHED.equals(styleValue)) { if (width > 1) { shortValue = CellStyle.BORDER_MEDIUM_DASHED; } else { shortValue = CellStyle.BORDER_DASHED; } } // border style if (shortValue != -1) { try { MethodUtils.invokeMethod(cellStyle, "setBorder" + posName, shortValue); } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } } } }
private String redirectWithLatestLinks(String wikiLink) { if (wikiLink == null) return "*null*"; String title = wikiLink.replace(' ', '_'); if (wikiLink.indexOf("http://en.wikipedia.org/wiki/") > -1) title = wikiLink.substring( wikiLink.lastIndexOf("http://en.wikipedia.org/wiki/") + "http://en.wikipedia.org/wiki/".length(), wikiLink.length()); title = redirect(title); return StringEscapeUtils.unescapeXml(StringUtils.capitalize(title)); }
/** * Appends a getter method for the attribute of html tag which contains the variable specified by * the name into the given string builder. * * @param methodBuilder {@link StringBuilder} the generated method will be appended to * @param variableName the variable name * @param attributeName the name of the attribute which contains template variables * @param assignedAttributeValue the attribute value assigned to the html tag * @param isRepeated the boolean whether the specified html tag appears in a repeated part */ private void appendAttributeGetter( StringBuilder methodBuilder, String variableName, String attributeName, String assignedAttributeValue, boolean isRepeated) { if (!isRepeated) { appendGetter( methodBuilder, variableName, ".getAttribute(\"" + attributeName + "\")", "String", "AttributeOf" + StringUtils.capitalize(attributeName) + "On"); } else { appendListGetter( methodBuilder, variableName, ".getAttribute(\"" + attributeName + "\")", "String", "AttributesOf" + StringUtils.capitalize(attributeName) + "On", assignedAttributeValue); } }
/** * Returns a value which indicates whether or not the document can be edited. * * @return a value which indicates whether or not the document can be edited */ @JsxGetter public String getDesignMode() { if (designMode_ == null) { if (getBrowserVersion().hasFeature(JS_DOCUMENT_DESIGN_MODE_INHERIT)) { designMode_ = "inherit"; } else { designMode_ = "off"; } if (getBrowserVersion().hasFeature(JS_DOCUMENT_DESIGN_MODE_CAPITAL_FIRST)) { designMode_ = StringUtils.capitalize(designMode_); } } return designMode_; }
private static String formatString(String name) { String[] temp = name.toLowerCase().split(" "); StringBuilder sb = new StringBuilder(); for (String string : temp) { if (string.contains("(")) { string = string.substring(0, string.indexOf("(")) + string.substring(string.indexOf("("), string.indexOf(")")).toUpperCase() + string.substring(string.indexOf(")")); } sb.append(StringUtils.capitalize(string)); sb.append(" "); } return sb.toString().trim(); }
@Override public Boolean evaluate(String expression) { if (runtimeOptions == null) { return true; } try { Method getter = OptionsBase.class.getMethod("is" + StringUtils.capitalize(expression)); boolean result = (Boolean) getter.invoke(runtimeOptions, new Object[] {}); LOG.info("Extension {} activated:{}", expression, result); return !result; } catch (Exception e) { ExceptionUtils.throwAsRuntimeException(e); return null; } }
private String toJavaName(final String file) { final StringBuilder builder = new StringBuilder(); boolean nextUpper = false; for (final char anIn : file.replace(".json", "").toCharArray()) { if (FORBIDDEN_JAVA_NAMES.contains(anIn)) { nextUpper = true; } else if (nextUpper) { builder.append(Character.toUpperCase(anIn)); nextUpper = false; } else { builder.append(anIn); } } return StringUtils.capitalize(builder.toString()); }
/** @return the availableThemes */ public SortedMap<String, String> getAvailableThemes() { synchronized (this) { if (availableThemes == null) { this.availableThemes = new TreeMap<String, String>(); List<HierarchicalConfiguration> configurations = configuration.configurationsAt("appearances.ui-theme.available-themes.theme"); for (HierarchicalConfiguration config : configurations) { String name = config.getString("[@name]"); availableThemes.put(StringUtils.capitalize(name), name); } } } return availableThemes; }
/** * Appends a getter method for the variable specified by the name or the result of invoking the * method described by the given prefix on the variable into the given string builder. * * @param builder {@link StringBuilder} the generated test code will be appended to * @param variableName the variable name * @param elementSuffixForInvoking the suffix of the {@code WebElement} variable that specifies a * method name with a dot to invoke it, e.g. {@literal".getText()"}, or an empty string to * access the variable directly. * @param returnType the return type of the generated getter method * @param methodNamePrefix the name prefix of the generated method */ private void appendGetter( StringBuilder builder, String variableName, String elementSuffixForInvoking, String returnType, String methodNamePrefix) { appendLine(builder); // TODO(kazuu): Help to select proper one from getFoo, getFoo2, getFoo3 ... appendLine( builder, 1, String.format( "public %s get%s%s() {", returnType, methodNamePrefix, StringUtils.capitalize(variableName))); appendLine(builder, 2, String.format("return %s%s;", variableName, elementSuffixForInvoking)); appendLine(builder, 1, "}"); }
@Override public String execute() throws Exception { List<String> values = Lists.newArrayList(); for (Schema schema : schemaService.getMetadataSchemas()) { values.add(schema.getPlural()); } Collections.sort(values); for (String key : values) { String[] camelCaseWords = StringUtils.capitalize(key).split("(?=[A-Z])"); exportClasses.put(key, StringUtils.join(camelCaseWords, " ")); } return SUCCESS; }