if (formSet != null) { if (getLog().isDebugEnabled()) { getLog().debug("FormSet[" + formSet.displayKey() + "] found - merging."); formSet = new FormSet(); formSet.setLanguage(language); formSet.setCountry(country); formSet.setVariant(variant); getLog().debug("FormSet[" + formSet.displayKey() + "] created.");
/** * Merges the given <code>FormSet</code> into this one. If any of <code>depends</code> * s <code>Forms</code> are not in this <code>FormSet</code> then, include * them, else merge both <code>Forms</code>. Theoretically we should only * merge a "parent" formSet. * * @param depends FormSet to be merged * @since Validator 1.2.0 */ protected void merge(FormSet depends) { if (depends != null) { Map<String, Form> pForms = getForms(); Map<String, Form> dForms = depends.getForms(); for (Iterator<Entry<String, Form>> it = dForms.entrySet().iterator(); it.hasNext(); ) { Entry<String, Form> entry = it.next(); String key = entry.getKey(); Form pForm = pForms.get(key); if (pForm != null) {//merge, but principal 'rules', don't overwrite // anything pForm.merge(entry.getValue()); } else {//just add addForm(entry.getValue()); } } } merged = true; }
/** * Builds a key to store the <code>FormSet</code> under based on it's * language, country, and variant values. * @param fs The Form Set. * @return generated key for a formset. */ protected String buildKey(FormSet fs) { return this.buildLocale(fs.getLanguage(), fs.getCountry(), fs.getVariant()); }
/** * Add a <code>Constant</code> to the locale level. * * @param name The constant name * @param value The constant value */ public void addConstant(String name, String value) { if (constants.containsKey(name)) { getLog().error("Constant '" + name + "' already exists in FormSet[" + this.displayKey() + "] - ignoring."); } else { constants.put(name, value); } }
/** * <p>Process the <code>Form</code> objects. This clones the <code>Field</code>s * that don't exist in a <code>FormSet</code> compared to its parent * <code>FormSet</code>.</p> */ private void processForms() { if (defaultFormSet == null) {// it isn't mandatory to have a // default formset defaultFormSet = new FormSet(); } defaultFormSet.process(getConstants()); // Loop through FormSets and merge if necessary for (Iterator<String> i = getFormSets().keySet().iterator(); i.hasNext();) { String key = i.next(); FormSet fs = getFormSets().get(key); fs.merge(getParent(fs)); } // Process Fully Constructed FormSets for (Iterator<FormSet> i = getFormSets().values().iterator(); i.hasNext();) { FormSet fs = i.next(); if (!fs.isProcessed()) { fs.process(getConstants()); } } }
private ValidatorResources setupDateResources(String property, String action) { ValidatorResources resources = new ValidatorResources(); ValidatorAction va = new ValidatorAction(); va.setName(action); va.setClassname("org.apache.commons.validator.ValidatorTest"); va.setMethod("formatDate"); va.setMethodParams("java.lang.Object,org.apache.commons.validator.Field"); FormSet fs = new FormSet(); Form form = new Form(); form.setName("testForm"); Field field = new Field(); field.setProperty(property); field.setDepends(action); form.addField(field); fs.addForm(form); resources.addValidatorAction(va); resources.addFormSet(fs); resources.process(); return resources; }
private void registerValidations(ModuleConfig config) { // Create Forms. ValidatorResources currentResources = getValidatorResources(config); FormSet formSet = new FormSet(); FormBeanConfig[] formConfigs = config.findFormBeanConfigs(); for (int i = 0; i < formConfigs.length; i++) { if (!registeredValidation(currentResources, formConfigs[i])) { Class clazz = ClassUtil.forName(formConfigs[i].getType()); String name = formConfigs[i].getName(); Form form = this.validationCreator.createForm(config, clazz, name); if (form != null) { formSet.addForm(form); if (log.isDebugEnabled()) { log.debug("auto register " + form); } } } } // Initialize ValidatorResources if (formSet.getForms().size() != 0) { ValidatorResources resources = new ValidatorResources(); resources.addFormSet(formSet); resources.process(); addValidatorResources(config, resources); } }
if (fs.getType() == FormSet.LANGUAGE_FORMSET) { parent = defaultFormSet; } else if (fs.getType() == FormSet.COUNTRY_FORMSET) { parent = getFormSets().get(buildLocale(fs.getLanguage(), null, null)); if (parent == null) { parent = defaultFormSet; } else if (fs.getType() == FormSet.VARIANT_FORMSET) { parent = getFormSets().get(buildLocale(fs.getLanguage(), fs .getCountry(), null)); if (parent == null) { parent = getFormSets().get(buildLocale(fs.getLanguage(), null, null)); if (parent == null) {
private FormSet createValidatorFormSet(TgwEntity entity, ActionMapping mapping) { FormSet fs = getFormSet(entity.getDomainName(), entity.getName()); Form form = new Form(); form.setName(mapping.getName()); for (TgwAttribute attr : entity.getAttributes()) { ValidatorUtils.bindField(form, attr); } // overide fs.addForm(form); return fs; } }
protected synchronized FormSet getFormSet(String schema, String name) { String key = schema + "." + name; FormSet formSet = formSetCache.get(key); if (formSet == null) { formSet = new FormSet(); formSetCache.put(key, formSet); } return formSet; }
/** * Returns a string representation of the object. * * @return A string representation */ @Override public String toString() { StringBuilder results = new StringBuilder(); results.append("FormSet: language="); results.append(language); results.append(" country="); results.append(country); results.append(" variant="); results.append(variant); results.append("\n"); for (Iterator<?> i = getForms().values().iterator(); i.hasNext(); ) { results.append(" "); results.append(i.next()); results.append("\n"); } return results.toString(); }
FormSet formSet = getFormSets().get(key); if (formSet != null) { form = formSet.getForm(formKey); FormSet formSet = getFormSets().get(key); if (formSet != null) { form = formSet.getForm(formKey); FormSet formSet = getFormSets().get(key); if (formSet != null) { form = formSet.getForm(formKey); form = defaultFormSet.getForm(formKey); key = "default";
/** * <p>Process the <code>Form</code> objects. This clones the <code>Field</code>s * that don't exist in a <code>FormSet</code> compared to its parent * <code>FormSet</code>.</p> */ private void processForms() { if (defaultFormSet == null) {// it isn't mandatory to have a // default formset defaultFormSet = new FormSet(); } defaultFormSet.process(hConstants); // Loop through FormSets and merge if necessary for (Iterator i = hFormSets.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); FormSet fs = (FormSet) hFormSets.get(key); fs.merge(getParent(fs)); } // Process Fully Constructed FormSets for (Iterator i = hFormSets.values().iterator(); i.hasNext();) { FormSet fs = (FormSet) i.next(); if (!fs.isProcessed()) { fs.process(hConstants); } } }
if (fs.getType() == FormSet.LANGUAGE_FORMSET) { parent = defaultFormSet; } else if (fs.getType() == FormSet.COUNTRY_FORMSET) { parent = (FormSet) hFormSets.get(buildLocale(fs.getLanguage(), null, null)); if (parent == null) { parent = defaultFormSet; } else if (fs.getType() == FormSet.VARIANT_FORMSET) { parent = (FormSet) hFormSets.get(buildLocale(fs.getLanguage(), fs .getCountry(), null)); if (parent == null) { parent = (FormSet) hFormSets.get(buildLocale(fs.getLanguage(), null, null)); if (parent == null) {
/** * Add a <code>Form</code> to the <code>FormSet</code>. * * @param f The form */ public void addForm(Form f) { String formName = f.getName(); if (forms.containsKey(formName)) { getLog().error("Form '" + formName + "' already exists in FormSet[" + this.displayKey() + "] - ignoring."); } else { forms.put(f.getName(), f); } }
private FormSet createFormSet() { FormSet fs = getFormSet(getEntity().getDomainName(), getFormName()); Form form = new Form(); form.setName(getActionMapping().getName()); for (TgwAttribute attr : getEntity().getAttributes()) { String attrName = attr.getName(); if (hasField(attrName)) { ValidatorUtils.bindField(form, attr); } } fs.addForm(form); return fs; } }
/** * Returns a string representation of the object. * * @return A string representation */ @Override public String toString() { StringBuilder results = new StringBuilder(); results.append("FormSet: language="); results.append(language); results.append(" country="); results.append(country); results.append(" variant="); results.append(variant); results.append("\n"); for (Iterator<?> i = getForms().values().iterator(); i.hasNext(); ) { results.append(" "); results.append(i.next()); results.append("\n"); } return results.toString(); }
FormSet formSet = (FormSet)hFormSets.get(key); if (formSet != null) { form = formSet.getForm(formKey); FormSet formSet = (FormSet)hFormSets.get(key); if (formSet != null) { form = formSet.getForm(formKey); FormSet formSet = (FormSet)hFormSets.get(key); if (formSet != null) { form = formSet.getForm(formKey); form = defaultFormSet.getForm(formKey); key = "default";
if (formSet != null) { if (getLog().isDebugEnabled()) { getLog().debug("FormSet[" + formSet.displayKey() + "] found - merging."); formSet = new FormSet(); formSet.setLanguage(language); formSet.setCountry(country); formSet.setVariant(variant); getLog().debug("FormSet[" + formSet.displayKey() + "] created.");