@Override protected void fillJDOMConfigElement(Element configElement) { super.fillJDOMConfigElement(configElement); if (null != this.getMinLength() && this.getMinLength() > -1) { Element element = new Element("minlength"); element.setText(String.valueOf(this.getMinLength())); configElement.addContent(element); } if (null != this.getMaxLength() && this.getMaxLength() > -1) { Element element = new Element("maxlength"); element.setText(String.valueOf(this.getMaxLength())); configElement.addContent(element); } if (null != this.getRegexp() && this.getRegexp().trim().length() > 0) { Element regexpElem = new Element("regexp"); CDATA cdata = new CDATA(this.getRegexp()); regexpElem.addContent(cdata); configElement.addContent(regexpElem); } String toStringEqualValue = (this.getValue() != null) ? String.valueOf(this.getValue()) : null; this.insertJDOMConfigElement("value", this.getValueAttribute(), toStringEqualValue, configElement); String toStringStartValue = (this.getRangeStart() != null) ? String.valueOf(this.getRangeStart()) : null; this.insertJDOMConfigElement("rangestart", this.getRangeStartAttribute(), toStringStartValue, configElement); String toStringEndValue = (this.getRangeEnd() != null) ? String.valueOf(this.getRangeEnd()) : null; this.insertJDOMConfigElement("rangeend", this.getRangeEndAttribute(), toStringEndValue, configElement); }
@Override protected void extractValidationRules(Element validationElement) { super.extractValidationRules(validationElement); String maxLength = this.extractValue(validationElement, "maxlength"); if (null != maxLength) { this.setMaxLength(Integer.parseInt(maxLength)); String minLength = this.extractValue(validationElement, "minlength"); if (null != minLength) { this.setMinLength(Integer.parseInt(minLength)); String regexp = this.extractValue(validationElement, "regexp"); if (null != regexp && regexp.trim().length() > 0) { this.setRegexp(regexp); this.setValue(valueElement.getText()); this.setValueAttribute(valueElement.getAttributeValue("attribute")); this.setRangeStart(rangeStartElement.getText()); this.setRangeStartAttribute(rangeStartElement.getAttributeValue("attribute")); this.setRangeEnd(rangeEndElement.getText()); this.setRangeEndAttribute(rangeEndElement.getAttributeValue("attribute"));
@Override public IAttributeValidationRules clone() { TextAttributeValidationRules clone = (TextAttributeValidationRules) super.clone(); clone.setMaxLength(this.getMaxLength()); clone.setMinLength(this.getMinLength()); clone.setRegexp(this.getRegexp()); return clone; }
@Override public boolean isEmpty() { return (super.isEmpty() && (null == this.getMaxLength() || this.getMaxLength() < 0) && (null == this.getMinLength() || this.getMinLength() < 0) && (null == this.getRegexp() || this.getRegexp().trim().length() == 0)); }
@Override protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action) { AttributeInterface attribute = attributeFieldError.getAttribute(); TextAttributeValidationRules valRules = (TextAttributeValidationRules) attribute.getValidationRules(); if (null != valRules) { ITextAttribute textAttribute = (ITextAttribute) attribute; String text = textAttribute.getTextForLang(null); String errorCode = attributeFieldError.getErrorCode(); if (errorCode.equals(FieldError.INVALID_MIN_LENGTH)) { String[] args = {String.valueOf(text.length()), String.valueOf(valRules.getMinLength())}; return action.getText("MonotextAttribute.fieldError.invalidMinLength", args); } else if (errorCode.equals(FieldError.INVALID_MAX_LENGTH)) { String[] args = {String.valueOf(text.length()), String.valueOf(valRules.getMaxLength())}; return action.getText("MonotextAttribute.fieldError.invalidMaxLength", args); } else if (errorCode.equals(FieldError.INVALID_FORMAT)) { return action.getText("MonotextAttribute.fieldError.invalidInsertedText"); } } return action.getText(this.getInvalidAttributeMessage()); }
protected void checkTextLengths(AttributeInterface attribute, AttributeTracer tracer, Lang lang, List<AttributeFieldError> errors) { Integer maxLength = this.getMaxLength(); Integer minLength = this.getMinLength(); if ((null != maxLength && maxLength > -1) || (null != minLength && minLength > -1)) { String text = this.getTextForCheckLength(attribute, lang); if (text != null && text.trim().length() > 0) { text = text.trim(); if ((null != maxLength && maxLength > -1) && text.length() > maxLength) { AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID_MAX_LENGTH, tracer); error.setMessage("Lang '" + lang.getDescr() + "' - length " + text.length() + " upper than " + maxLength); errors.add(error); } if ((null != minLength && minLength > -1) && text.length() < minLength) { AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID_MIN_LENGTH, tracer); error.setMessage("Lang '" + lang.getDescr() + "' - length " + text.length() + " lower than " + minLength); errors.add(error); } } } }
@Override public String getRegexp() { return ((TextAttributeValidationRules) this.getValidationRules()).getRegexp(); }
@Override @Deprecated (/** to guaranted compatibility with previsous version of jAPS 2.0.12 */) public void setMaxLength(int maxLength) { ((TextAttributeValidationRules) this.getValidationRules()).setMaxLength(maxLength); }
@Override public int getMaxLength() { TextAttributeValidationRules validationRule = (TextAttributeValidationRules) this.getValidationRules(); if (null != validationRule && null != validationRule.getMaxLength()) { return validationRule.getMaxLength(); } return -1; }
@Override public int getMinLength() { TextAttributeValidationRules validationRule = (TextAttributeValidationRules) this.getValidationRules(); if (null != validationRule && null != validationRule.getMinLength()) { return validationRule.getMinLength(); } return -1; }
@Override public IAttributeValidationRules clone() { TextAttributeValidationRules clone = (TextAttributeValidationRules) super.clone(); clone.setMaxLength(this.getMaxLength()); clone.setMinLength(this.getMinLength()); clone.setRegexp(this.getRegexp()); return clone; }
@Override protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action) { AttributeInterface attribute = attributeFieldError.getAttribute(); TextAttributeValidationRules valRules = (TextAttributeValidationRules) attribute.getValidationRules(); if (null != valRules) { ITextAttribute textAttribute = (ITextAttribute) attribute; String text = textAttribute.getTextForLang(null); String errorCode = attributeFieldError.getErrorCode(); if (errorCode.equals(FieldError.INVALID_MIN_LENGTH)) { String[] args = {String.valueOf(text.length()), String.valueOf(valRules.getMinLength())}; return action.getText("MonotextAttribute.fieldError.invalidMinLength", args); } else if (errorCode.equals(FieldError.INVALID_MAX_LENGTH)) { String[] args = {String.valueOf(text.length()), String.valueOf(valRules.getMaxLength())}; return action.getText("MonotextAttribute.fieldError.invalidMaxLength", args); } else if (errorCode.equals(FieldError.INVALID_FORMAT)) { return action.getText("MonotextAttribute.fieldError.invalidInsertedText"); } } return action.getText(this.getInvalidAttributeMessage()); }
@Override public boolean isEmpty() { return (super.isEmpty() && (null == this.getMaxLength() || this.getMaxLength() < 0) && (null == this.getMinLength() || this.getMinLength() < 0) && (null == this.getRegexp() || this.getRegexp().trim().length() == 0)); }
protected void checkTextLengths(AttributeInterface attribute, AttributeTracer tracer, Lang lang, List<AttributeFieldError> errors) { Integer maxLength = this.getMaxLength(); Integer minLength = this.getMinLength(); if ((null != maxLength && maxLength > -1) || (null != minLength && minLength > -1)) { String text = this.getTextForCheckLength(attribute, lang); if (text != null && text.trim().length() > 0) { text = text.trim(); if ((null != maxLength && maxLength > -1) && text.length() > maxLength) { AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID_MAX_LENGTH, tracer); error.setMessage("Lang '" + lang.getDescr() + "' - length " + text.length() + " upper than " + maxLength); errors.add(error); } if ((null != minLength && minLength > -1) && text.length() < minLength) { AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID_MIN_LENGTH, tracer); error.setMessage("Lang '" + lang.getDescr() + "' - length " + text.length() + " lower than " + minLength); errors.add(error); } } } }
@Override public String getRegexp() { return ((TextAttributeValidationRules) this.getValidationRules()).getRegexp(); }
@Override @Deprecated (/** to guaranted compatibility with previsous version of jAPS 2.0.12 */) public void setMaxLength(int maxLength) { ((TextAttributeValidationRules) this.getValidationRules()).setMaxLength(maxLength); }
@Override public int getMaxLength() { TextAttributeValidationRules validationRule = (TextAttributeValidationRules) this.getValidationRules(); if (null != validationRule && null != validationRule.getMaxLength()) { return validationRule.getMaxLength(); } return -1; }
@Override public int getMinLength() { TextAttributeValidationRules validationRule = (TextAttributeValidationRules) this.getValidationRules(); if (null != validationRule && null != validationRule.getMinLength()) { return validationRule.getMinLength(); } return -1; }
@Override protected void fillJDOMConfigElement(Element configElement) { super.fillJDOMConfigElement(configElement); if (null != this.getMinLength() && this.getMinLength() > -1) { Element element = new Element("minlength"); element.setText(String.valueOf(this.getMinLength())); configElement.addContent(element); } if (null != this.getMaxLength() && this.getMaxLength() > -1) { Element element = new Element("maxlength"); element.setText(String.valueOf(this.getMaxLength())); configElement.addContent(element); } if (null != this.getRegexp() && this.getRegexp().trim().length() > 0) { Element regexpElem = new Element("regexp"); CDATA cdata = new CDATA(this.getRegexp()); regexpElem.addContent(cdata); configElement.addContent(regexpElem); } String toStringEqualValue = (this.getValue() != null) ? String.valueOf(this.getValue()) : null; this.insertJDOMConfigElement("value", this.getValueAttribute(), toStringEqualValue, configElement); String toStringStartValue = (this.getRangeStart() != null) ? String.valueOf(this.getRangeStart()) : null; this.insertJDOMConfigElement("rangestart", this.getRangeStartAttribute(), toStringStartValue, configElement); String toStringEndValue = (this.getRangeEnd() != null) ? String.valueOf(this.getRangeEnd()) : null; this.insertJDOMConfigElement("rangeend", this.getRangeEndAttribute(), toStringEndValue, configElement); }
@Override protected void extractValidationRules(Element validationElement) { super.extractValidationRules(validationElement); String maxLength = this.extractValue(validationElement, "maxlength"); if (null != maxLength) { this.setMaxLength(Integer.parseInt(maxLength)); String minLength = this.extractValue(validationElement, "minlength"); if (null != minLength) { this.setMinLength(Integer.parseInt(minLength)); String regexp = this.extractValue(validationElement, "regexp"); if (null != regexp && regexp.trim().length() > 0) { this.setRegexp(regexp); this.setValue(valueElement.getText()); this.setValueAttribute(valueElement.getAttributeValue("attribute")); this.setRangeStart(rangeStartElement.getText()); this.setRangeStartAttribute(rangeStartElement.getAttributeValue("attribute")); this.setRangeEnd(rangeEndElement.getText()); this.setRangeEndAttribute(rangeEndElement.getAttributeValue("attribute"));