/** Builds query parameter line by figuring out what should be submitted */ private StringBuilder buildParameterList(Method method, StringBuilder query) { for (Parameter p : ReflectionUtils.getParameters(method)) { QueryParameter qp = p.annotation(QueryParameter.class); if (qp != null) { String name = qp.value(); if (name.length() == 0) name = p.name(); if (name == null || name.length() == 0) continue; // unknown parameter name. we'll report the error when the form is submitted. RelativePath rp = p.annotation(RelativePath.class); if (rp != null) name = rp.value() + '/' + name; if (query.length() == 0) query.append("+qs(this)"); if (name.equals("value")) { // The special 'value' parameter binds to the the current field query.append(".addThis()"); } else { query.append(".nearBy('" + name + "')"); } continue; } Method m = ReflectionUtils.getPublicMethodNamed(p.type(), "fromStapler"); if (m != null) buildParameterList(m, query); } return query; }
private String calcCheckUrl(String fieldName) { String capitalizedFieldName = StringUtils.capitalize(fieldName); Method method = ReflectionUtils.getPublicMethodNamed(getClass(), "doCheck" + capitalizedFieldName); if (method == null) return NONE; return singleQuote(getDescriptorUrl() + "/check" + capitalizedFieldName) + buildParameterList(method, new StringBuilder()).append(".toString()"); }
/** Computes the auto-completion setting */ public void calcAutoCompleteSettings(String field, Map<String, Object> attributes) { String capitalizedFieldName = StringUtils.capitalize(field); String methodName = "doAutoComplete" + capitalizedFieldName; Method method = ReflectionUtils.getPublicMethodNamed(getClass(), methodName); if (method == null) return; // no auto-completion attributes.put( "autoCompleteUrl", String.format( "%s/%s/autoComplete%s", getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName)); }
private List<String> buildFillDependencies(Method method, List<String> depends) { for (Parameter p : ReflectionUtils.getParameters(method)) { QueryParameter qp = p.annotation(QueryParameter.class); if (qp != null) { String name = qp.value(); if (name.length() == 0) name = p.name(); if (name == null || name.length() == 0) continue; // unknown parameter name. we'll report the error when the form is submitted. RelativePath rp = p.annotation(RelativePath.class); if (rp != null) name = rp.value() + '/' + name; depends.add(name); continue; } Method m = ReflectionUtils.getPublicMethodNamed(p.type(), "fromStapler"); if (m != null) buildFillDependencies(m, depends); } return depends; }
/** * Computes the list of other form fields that the given field depends on, via the doFillXyzItems * method, and sets that as the 'fillDependsOn' attribute. Also computes the URL of the * doFillXyzItems and sets that as the 'fillUrl' attribute. */ public void calcFillSettings(String field, Map<String, Object> attributes) { String capitalizedFieldName = StringUtils.capitalize(field); String methodName = "doFill" + capitalizedFieldName + "Items"; Method method = ReflectionUtils.getPublicMethodNamed(getClass(), methodName); if (method == null) throw new IllegalStateException( String.format( "%s doesn't have the %s method for filling a drop-down list", getClass(), methodName)); // build query parameter line by figuring out what should be submitted List<String> depends = buildFillDependencies(method, new ArrayList<String>()); if (!depends.isEmpty()) attributes.put("fillDependsOn", Util.join(depends, " ")); attributes.put( "fillUrl", String.format( "%s/%s/fill%sItems", getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName)); }