@@ -32,61 +32,60 @@
* @author E.Santoboni
*/
public class CompositeAttributeManager extends AbstractAttributeManager {

@Override
@Deprecated
protected void checkAttribute(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkAttribute(action, attribute, tracer, entity);
this.manageCompositeAttribute(true, false, action, attribute, tracer, null, entity);
}

@Override
protected void updateAttribute(AttributeInterface attribute, AttributeTracer tracer, HttpServletRequest request) {
this.manageCompositeAttribute(false, true, null, attribute, tracer, request, null);
}

private void manageCompositeAttribute(boolean isCheck, boolean isUpdate, ActionSupport action,
AttributeInterface attribute, AttributeTracer tracer, HttpServletRequest request, IApsEntity entity) {
List<AttributeInterface> attributes = ((CompositeAttribute) attribute).getAttributes();
for (int i=0; i<attributes.size(); i++) {
AttributeInterface attributeElement = attributes.get(i);
AttributeTracer elementTracer = (AttributeTracer) tracer.clone();
elementTracer.setCompositeElement(true);
elementTracer.setParentAttribute(attribute);
AbstractAttributeManager elementManager = (AbstractAttributeManager) this.getManager(attributeElement.getType());
if (elementManager != null) {
if (isCheck && !isUpdate) {
elementManager.checkAttribute(action, attributeElement, elementTracer, entity);
}
if (!isCheck && isUpdate) {
elementManager.updateAttribute(attributeElement, elementTracer, request);
}
}
}
}

@Override
@Deprecated
protected int getState(AttributeInterface attribute, AttributeTracer tracer) {
boolean isVoid = true;
List<AttributeInterface> attributes = ((CompositeAttribute) attribute).getAttributes();
for (int i=0; i<attributes.size(); i++) {
AttributeInterface attributeElement = attributes.get(i);
AbstractAttributeManager elementManager = (AbstractAttributeManager) this.getManager(attributeElement.getType());
if (elementManager != null) {
AttributeTracer elementTracer = (AttributeTracer) tracer.clone();
elementTracer.setCompositeElement(true);
elementTracer.setParentAttribute(attribute);
int state = elementManager.getState(attributeElement, elementTracer);
if (state != this.EMPTY_ATTRIBUTE_STATE) {
isVoid = false;
break;
}
}
}
if (!isVoid) {
return VALUED_ATTRIBUTE_STATE;
} else return EMPTY_ATTRIBUTE_STATE;
}


@Deprecated
protected void checkAttribute(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkAttribute(action, attribute, tracer, entity);
this.manageCompositeAttribute(true, false, action, attribute, tracer, null, entity);
}

protected void updateAttribute(AttributeInterface attribute, AttributeTracer tracer, HttpServletRequest request) {
this.manageCompositeAttribute(false, true, null, attribute, tracer, request, null);
}

private void manageCompositeAttribute(boolean isCheck, boolean isUpdate, ActionSupport action,
AttributeInterface attribute, AttributeTracer tracer, HttpServletRequest request, IApsEntity entity) {
List<AttributeInterface> attributes = ((CompositeAttribute) attribute).getAttributes();
for (int i = 0; i < attributes.size(); i++) {
AttributeInterface attributeElement = attributes.get(i);
AttributeTracer elementTracer = (AttributeTracer) tracer.clone();
elementTracer.setCompositeElement(true);
elementTracer.setParentAttribute(attribute);
AbstractAttributeManager elementManager = (AbstractAttributeManager) this.getManager(attributeElement.getType());
if (elementManager != null) {
if (isCheck && !isUpdate) {
elementManager.checkAttribute(action, attributeElement, elementTracer, entity);
}
if (!isCheck && isUpdate) {
elementManager.updateAttribute(attributeElement, elementTracer, request);
}
}
}
}

@Deprecated
protected int getState(AttributeInterface attribute, AttributeTracer tracer) {
boolean isVoid = true;
List<AttributeInterface> attributes = ((CompositeAttribute) attribute).getAttributes();
for (int i = 0; i < attributes.size(); i++) {
AttributeInterface attributeElement = attributes.get(i);
AbstractAttributeManager elementManager = (AbstractAttributeManager) this.getManager(attributeElement.getType());
if (elementManager != null) {
AttributeTracer elementTracer = (AttributeTracer) tracer.clone();
elementTracer.setCompositeElement(true);
elementTracer.setParentAttribute(attribute);
int state = elementManager.getState(attributeElement, elementTracer);
if (state != this.EMPTY_ATTRIBUTE_STATE) {
isVoid = false;
break;
}
}
}
if (!isVoid) {
return VALUED_ATTRIBUTE_STATE;
} else {
return EMPTY_ATTRIBUTE_STATE;
}
}

}
@@ -17,6 +17,8 @@
*/
package com.agiletec.apsadmin.system.entity.attribute.manager;

import com.agiletec.aps.system.ApsSystemUtils;
import com.agiletec.aps.system.common.entity.model.AttributeFieldError;
import com.agiletec.aps.system.common.entity.model.FieldError;

import java.text.ParseException;
@@ -145,18 +147,40 @@ private void validateDate(ActionSupport action, AttributeInterface attribute, At
}
}

protected String getCustomAttributeErrorMessage(String errorCode, ActionSupport action, AttributeInterface attribute) {
public void validate(ActionSupport action, com.agiletec.aps.system.common.entity.model.AttributeTracer tracer, AttributeInterface attribute) {
try {
super.validate(action, tracer, attribute);
if (((DateAttribute) attribute).getDate() != null) return;
String insertedDateString = ((DateAttribute) attribute).getFailedDateString();
if (null != insertedDateString
&& insertedDateString.trim().length() > 0
&& !CheckFormatUtil.isValidDate(insertedDateString)) {
AttributeFieldError attributeFieldError = new AttributeFieldError(attribute, FieldError.INVALID_FORMAT, tracer);
this.addFieldError(action, attribute, attributeFieldError);
}
} catch (Throwable t) {
ApsSystemUtils.logThrowable(t, this, "validate");
throw new RuntimeException("Error validating date attribute", t);
}
}

protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action, AttributeInterface attribute) {
DateAttributeValidationRules valRule = (DateAttributeValidationRules) attribute.getValidationRules();
if (null != valRule) {
String errorCode = attributeFieldError.getErrorCode();
System.out.println("////////// " + errorCode);
if (errorCode.equals(FieldError.GREATER_THAN_ALLOWED)) {
System.out.println("MMMMMMMMMMMMMMMMMMM");
Date endValue = (valRule.getRangeEnd() != null) ? (Date) valRule.getRangeEnd() : this.getOtherAttributeValue(attribute, valRule.getRangeEndAttribute());
String[] args = {DateConverter.getFormattedDate(endValue, "dd/MM/yyyy")};
return action.getText("DateAttribute.fieldError.greaterValue", args);
} else if (errorCode.equals(FieldError.LESS_THAN_ALLOWED)) {
System.out.println("NNNNNNNNNNNNNNNNNNNNNNNNN");
Date startValue = (valRule.getRangeStart() != null) ? (Date) valRule.getRangeStart() : this.getOtherAttributeValue(attribute, valRule.getRangeStartAttribute());
String[] args = {DateConverter.getFormattedDate(startValue, "dd/MM/yyyy")};
return action.getText("DateAttribute.fieldError.lessValue", args);
} else if (errorCode.equals(FieldError.NOT_EQUALS_THAN_ALLOWED)) {
System.out.println("OOOOOOOOOOOOOOOOOOOOOOOOOO");
Date value = (valRule.getValue() != null) ? (Date) valRule.getValue() : this.getOtherAttributeValue(attribute, valRule.getValueAttribute());
String[] args = {DateConverter.getFormattedDate(value, "dd/MM/yyyy")};
return action.getText("DateAttribute.fieldError.wrongValue", args);
@@ -26,15 +26,15 @@
* @deprecated
*/
public class HypertextAttributeManager extends TextAttributeManager {
@Override
protected String getTextForCheckLength(AttributeInterface attribute, Lang lang) {
String text = super.getTextForCheckLength(attribute, lang);
if (text != null) {
// remove HTML tags, entities an multiple spaces
text = text.replaceAll("<[^<>]+>", " ").replaceAll("&nbsp;", " ").replaceAll("\\&[^\\&;]+;", "_").replaceAll("([\t\n\r\f ])++", " ").trim();
}
return text;
}
@Override
protected String getTextForCheckLength(AttributeInterface attribute, Lang lang) {
String text = super.getTextForCheckLength(attribute, lang);
if (text != null) {
// remove HTML tags, entities an multiple spaces
text = text.replaceAll("<[^<>]+>", " ").replaceAll("&nbsp;", " ").replaceAll("\\&[^\\&;]+;", "_").replaceAll("([\t\n\r\f ])++", " ").trim();
}
return text;
}
}
@@ -17,6 +17,9 @@
*/
package com.agiletec.apsadmin.system.entity.attribute.manager;

import com.agiletec.aps.system.ApsSystemUtils;
import com.agiletec.aps.system.common.entity.model.AttributeFieldError;
import com.agiletec.aps.system.common.entity.model.FieldError;
import java.math.BigDecimal;

import com.agiletec.aps.system.common.entity.model.IApsEntity;
@@ -32,116 +35,161 @@
* @author E.Santoboni
*/
public class NumberAttributeManager extends AbstractMonoLangAttributeManager {

@Override
protected void setValue(AttributeInterface attribute, String value) {
NumberAttribute numberAttribute = (NumberAttribute) attribute;
BigDecimal number = null;
if (value != null) value = value.trim();
if (CheckFormatUtil.isValidNumber(value)) {
try {
number = new BigDecimal(value);
numberAttribute.setFailedNumberString(null);
} catch (NumberFormatException e) {
throw new RuntimeException("The submitted string is not recognized as a valid number - " + value + " -");
}
} else {
numberAttribute.setFailedNumberString(value);
}
numberAttribute.setValue(number);
}

@Override
protected Object getValue(AttributeInterface attribute) {
return ((NumberAttribute) attribute).getValue();
}

@Override
protected int getState(AttributeInterface attribute, AttributeTracer tracer) {
int state = super.getState(attribute, tracer);
boolean valuedString = ((NumberAttribute) attribute).getFailedNumberString() != null;
if (state == VALUED_ATTRIBUTE_STATE || valuedString) return this.VALUED_ATTRIBUTE_STATE;
return this.EMPTY_ATTRIBUTE_STATE;
}

@Override
protected void checkSingleAttribute(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkSingleAttribute(action, attribute, tracer, entity);
this.checkNumber(action, attribute, tracer);
this.validateNumber(action, attribute, tracer);
}

@Override
protected void checkListElement(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkListElement(action, attribute, tracer, entity);
this.checkNumber(action, attribute, tracer);
this.validateNumber(action, attribute, tracer);
}

@Override
protected void checkMonoListCompositeElement(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkMonoListCompositeElement(action, attribute, tracer, entity);
this.checkNumber(action, attribute, tracer);
this.validateNumber(action, attribute, tracer);
}

@Override
protected void checkMonoListElement(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkMonoListElement(action, attribute, tracer, entity);
this.checkNumber(action, attribute, tracer);
this.validateNumber(action, attribute, tracer);
}

private void checkNumber(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer) {
if (this.getState(attribute, tracer) == VALUED_ATTRIBUTE_STATE && !this.hasRightValue(attribute)) {
this.addFieldError(action, attribute, tracer, "NumberAttribute.fieldError.invalidNumber", null);
}
}

private void validateNumber(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer) {
if (this.getState(attribute, tracer) == VALUED_ATTRIBUTE_STATE && this.hasRightValue(attribute)) {
NumberAttributeValidationRules valRules = (NumberAttributeValidationRules) attribute.getValidationRules();
Integer attributeValue = ((NumberAttribute) attribute).getValue().intValue();
Integer startValue = (valRules.getRangeStart() != null) ? (Integer) valRules.getRangeStart() : this.getOtherAttributeValue(attribute, valRules.getRangeStartAttribute());
if (null != startValue && attributeValue < startValue) {
String[] args = {startValue.toString()};
this.addFieldError(action, attribute, tracer, "NumberAttribute.fieldError.lessValue", args);
}
Integer endValue = (valRules.getRangeEnd() != null) ? (Integer) valRules.getRangeEnd() : this.getOtherAttributeValue(attribute, valRules.getRangeEndAttribute());
if (null != endValue && attributeValue > endValue) {
String[] args = {endValue.toString()};
this.addFieldError(action, attribute, tracer, "NumberAttribute.fieldError.greaterValue", args);
}
Integer value = (valRules.getValue() != null) ? (Integer) valRules.getValue() : this.getOtherAttributeValue(attribute, valRules.getValueAttribute());
if (null != value && attributeValue != value) {
String[] args = {value.toString()};
this.addFieldError(action, attribute, tracer, "NumberAttribute.fieldError.wrongValue", args);
}
}
}

private Integer getOtherAttributeValue(AttributeInterface attribute, String otherAttributeName) {
AttributeInterface other = (AttributeInterface) attribute.getParentEntity().getAttribute(otherAttributeName);
if (null != other && (other instanceof NumberAttribute) && ((NumberAttribute) other).getValue() != null) {
return ((NumberAttribute) other).getValue().intValue();
}
return null;
}

/**
* Check for the coherency of the data of the attribute.
* @param attribute The attribute to check.
* @return true if the attribute is properly valued, false otherwise.
*/
private boolean hasRightValue(AttributeInterface attribute) {
if (this.getValue(attribute) != null) return true;
String insertedNumberString = ((NumberAttribute) attribute).getFailedNumberString();
return CheckFormatUtil.isValidNumber(insertedNumberString);
}

@Override
protected String getInvalidAttributeMessage() {
return "NumberAttribute.fieldError.invalidNumber";
}


protected void setValue(AttributeInterface attribute, String value) {
NumberAttribute numberAttribute = (NumberAttribute) attribute;
BigDecimal number = null;
if (value != null) {
value = value.trim();
}
if (CheckFormatUtil.isValidNumber(value)) {
try {
number = new BigDecimal(value);
numberAttribute.setFailedNumberString(null);
} catch (NumberFormatException e) {
throw new RuntimeException("The submitted string is not recognized as a valid number - " + value + " -");
}
} else {
numberAttribute.setFailedNumberString(value);
}
numberAttribute.setValue(number);
}

@Deprecated
protected Object getValue(AttributeInterface attribute) {
return ((NumberAttribute) attribute).getValue();
}

@Deprecated
protected int getState(AttributeInterface attribute, AttributeTracer tracer) {
int state = super.getState(attribute, tracer);
boolean valuedString = ((NumberAttribute) attribute).getFailedNumberString() != null;
if (state == VALUED_ATTRIBUTE_STATE || valuedString) {
return this.VALUED_ATTRIBUTE_STATE;
}
return this.EMPTY_ATTRIBUTE_STATE;
}

@Deprecated
protected void checkSingleAttribute(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkSingleAttribute(action, attribute, tracer, entity);
this.checkNumber(action, attribute, tracer);
this.validateNumber(action, attribute, tracer);
}

@Deprecated
protected void checkListElement(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkListElement(action, attribute, tracer, entity);
this.checkNumber(action, attribute, tracer);
this.validateNumber(action, attribute, tracer);
}

@Deprecated
protected void checkMonoListCompositeElement(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkMonoListCompositeElement(action, attribute, tracer, entity);
this.checkNumber(action, attribute, tracer);
this.validateNumber(action, attribute, tracer);
}

@Deprecated
protected void checkMonoListElement(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkMonoListElement(action, attribute, tracer, entity);
this.checkNumber(action, attribute, tracer);
this.validateNumber(action, attribute, tracer);
}

@Deprecated
private void checkNumber(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer) {
if (this.getState(attribute, tracer) == VALUED_ATTRIBUTE_STATE && !this.hasRightValue(attribute)) {
this.addFieldError(action, attribute, tracer, "NumberAttribute.fieldError.invalidNumber", null);
}
}

@Deprecated
private void validateNumber(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer) {
if (this.getState(attribute, tracer) == VALUED_ATTRIBUTE_STATE && this.hasRightValue(attribute)) {
NumberAttributeValidationRules valRules = (NumberAttributeValidationRules) attribute.getValidationRules();
Integer attributeValue = ((NumberAttribute) attribute).getValue().intValue();
Integer startValue = (valRules.getRangeStart() != null) ? (Integer) valRules.getRangeStart() : this.getOtherAttributeValue(attribute, valRules.getRangeStartAttribute());
if (null != startValue && attributeValue < startValue) {
String[] args = {startValue.toString()};
this.addFieldError(action, attribute, tracer, "NumberAttribute.fieldError.lessValue", args);
}
Integer endValue = (valRules.getRangeEnd() != null) ? (Integer) valRules.getRangeEnd() : this.getOtherAttributeValue(attribute, valRules.getRangeEndAttribute());
if (null != endValue && attributeValue > endValue) {
String[] args = {endValue.toString()};
this.addFieldError(action, attribute, tracer, "NumberAttribute.fieldError.greaterValue", args);
}
Integer value = (valRules.getValue() != null) ? (Integer) valRules.getValue() : this.getOtherAttributeValue(attribute, valRules.getValueAttribute());
if (null != value && attributeValue != value) {
String[] args = {value.toString()};
this.addFieldError(action, attribute, tracer, "NumberAttribute.fieldError.wrongValue", args);
}
}
}

public void validate(ActionSupport action, com.agiletec.aps.system.common.entity.model.AttributeTracer tracer, AttributeInterface attribute) {
try {
super.validate(action, tracer, attribute);
if (((NumberAttribute) attribute).getValue() != null) return;
String insertedNumberString = ((NumberAttribute) attribute).getFailedNumberString();
if (null != insertedNumberString
&& insertedNumberString.trim().length() > 0
&& !CheckFormatUtil.isValidNumber(insertedNumberString)) {
AttributeFieldError attributeFieldError = new AttributeFieldError(attribute, FieldError.INVALID_FORMAT, tracer);
this.addFieldError(action, attribute, attributeFieldError);
}
} catch (Throwable t) {
ApsSystemUtils.logThrowable(t, this, "validate");
throw new RuntimeException("Error validating number attribute", t);
}
}

protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action, AttributeInterface attribute) {
NumberAttributeValidationRules valRules = (NumberAttributeValidationRules) attribute.getValidationRules();
if (null != valRules) {
String errorCode = attributeFieldError.getErrorCode();
if (errorCode.equals(FieldError.LESS_THAN_ALLOWED)) {
Integer startValue = (valRules.getRangeStart() != null) ? (Integer) valRules.getRangeStart() : this.getOtherAttributeValue(attribute, valRules.getRangeStartAttribute());
String[] args = {startValue.toString()};
return action.getText("NumberAttribute.fieldError.lessValue", args);
} else if (errorCode.equals(FieldError.GREATER_THAN_ALLOWED)) {
Integer endValue = (valRules.getRangeEnd() != null) ? (Integer) valRules.getRangeEnd() : this.getOtherAttributeValue(attribute, valRules.getRangeEndAttribute());
String[] args = {endValue.toString()};
return action.getText("NumberAttribute.fieldError.greaterValue", args);
} else if (errorCode.equals(FieldError.NOT_EQUALS_THAN_ALLOWED)) {
Integer value = (valRules.getValue() != null) ? (Integer) valRules.getValue() : this.getOtherAttributeValue(attribute, valRules.getValueAttribute());
String[] args = {value.toString()};
return action.getText("NumberAttribute.fieldError.wrongValue", args);
}
}
return action.getText(this.getInvalidAttributeMessage());
}

private Integer getOtherAttributeValue(AttributeInterface attribute, String otherAttributeName) {
AttributeInterface other = (AttributeInterface) attribute.getParentEntity().getAttribute(otherAttributeName);
if (null != other && (other instanceof NumberAttribute) && ((NumberAttribute) other).getValue() != null) {
return ((NumberAttribute) other).getValue().intValue();
}
return null;
}

/**
* Check for the coherency of the data of the attribute.
* @param attribute The attribute to check.
* @return true if the attribute is properly valued, false otherwise.
* @deprecated
*/
private boolean hasRightValue(AttributeInterface attribute) {
if (this.getValue(attribute) != null) {
return true;
}
String insertedNumberString = ((NumberAttribute) attribute).getFailedNumberString();
return CheckFormatUtil.isValidNumber(insertedNumberString);
}

protected String getInvalidAttributeMessage() {
return "NumberAttribute.fieldError.invalidNumber";
}

}
@@ -17,6 +17,8 @@
*/
package com.agiletec.apsadmin.system.entity.attribute.manager;

import com.agiletec.aps.system.common.entity.model.AttributeFieldError;
import com.agiletec.aps.system.common.entity.model.FieldError;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -25,6 +27,7 @@
import com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface;
import com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute;
import com.agiletec.aps.system.common.entity.model.attribute.TextAttribute;
import com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules;
import com.agiletec.aps.system.services.lang.Lang;
import com.agiletec.apsadmin.system.entity.attribute.AttributeTracer;
import com.opensymphony.xwork2.ActionSupport;
@@ -35,20 +38,16 @@
*/
public class TextAttributeManager extends AbstractMultiLangAttributeManager {

@Override
@Deprecated
protected Object getValue(AttributeInterface attribute, Lang lang) {
return ((TextAttribute) attribute).getTextMap().get(lang.getCode());
}

/**
* This applies to simple XML test, hypertext, link and resource.
*/
@Override
protected void setValue(AttributeInterface attribute, Lang lang, String value) {
((TextAttribute) attribute).setText(value, lang.getCode());
}
@Override
@Deprecated
protected void checkSingleAttribute(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
AttributeTracer textTracer = (AttributeTracer) tracer.clone();
Lang defaultLang = this.getLangManager().getDefaultLang();
@@ -57,18 +56,19 @@ protected void checkSingleAttribute(ActionSupport action, AttributeInterface att
this.checkText(action, attribute, tracer);
}

@Override
@Deprecated
protected void checkMonoListCompositeElement(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkMonoListCompositeElement(action, attribute, tracer, entity);
this.checkText(action, attribute, tracer);
}

@Override
@Deprecated
protected void checkMonoListElement(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
super.checkMonoListElement(action, attribute, tracer, entity);
this.checkText(action, attribute, tracer);
}

@Deprecated
protected void checkText(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer) {
Iterator<Lang> langsIter = this.getLangManager().getLangs().iterator();
while (langsIter.hasNext()) {
@@ -80,6 +80,7 @@ protected void checkText(ActionSupport action, AttributeInterface attribute, Att
}
}

@Deprecated
protected void checkTextLengths(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, Lang lang) {
int maxLength = ((ITextAttribute) attribute).getMaxLength();
int minLength = ((ITextAttribute) attribute).getMinLength();
@@ -99,6 +100,7 @@ protected void checkTextLengths(ActionSupport action, AttributeInterface attribu
}
}

@Deprecated
protected void checkRegExp(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, Lang lang) {
String value = (String) this.getValue(attribute, lang);
ITextAttribute textAttribute = (ITextAttribute) attribute;
@@ -112,8 +114,33 @@ protected void checkRegExp(ActionSupport action, AttributeInterface attribute, A
}
}

@Deprecated
protected String getTextForCheckLength(AttributeInterface attribute, Lang lang) {
return (String) this.getValue(attribute, lang);
}


protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action, AttributeInterface attribute) {
TextAttributeValidationRules valRules = (TextAttributeValidationRules) attribute.getValidationRules();
if (null != valRules) {
ITextAttribute textAttribute = (ITextAttribute) attribute;
Lang lang = attributeFieldError.getTracer().getLang();
String langCode = (null != lang) ? lang.getCode() : null;
String text = textAttribute.getTextForLang(langCode);
String errorCode = attributeFieldError.getErrorCode();
if (errorCode.equals(FieldError.INVALID_MIN_LENGTH)) {
String[] args = {String.valueOf(text.length()), String.valueOf(valRules.getMaxLength()), lang.getDescr()};
return action.getText("TextAttribute.fieldError.invalidMaxLength", args);
} else if (errorCode.equals(FieldError.INVALID_MIN_LENGTH)) {
String[] args = {String.valueOf(text.length()), String.valueOf(valRules.getMinLength()), lang.getDescr()};
return action.getText("TextAttribute.fieldError.invalidMinLength", args);
} else if (errorCode.equals(FieldError.INVALID_FORMAT)) {
String[] args = {lang.getDescr()};
return action.getText("TextAttribute.fieldError.invalidInsertedText", args);
}
}
return action.getText(this.getInvalidAttributeMessage());
}


}
@@ -141,6 +141,8 @@ public List<AttributeFieldError> validate(AttributeTracer tracer) {
List<Lang> langs = langManager.getLangs();
for (int i = 0; i < langs.size(); i++) {
Lang lang = langs.get(i);
AttributeTracer textTracer = (AttributeTracer) tracer.clone();
textTracer.setLang(lang);
String text = this.getTextMap().get(lang.getCode());
if (null == text) continue;
List<SymbolicLink> links = HypertextAttributeUtil.getSymbolicLinksOnText(text);
@@ -152,7 +154,7 @@ public List<AttributeFieldError> validate(AttributeTracer tracer) {
SymbolicLink symbLink = links.get(j);
String linkErrorCode = sler.scan(symbLink, (Content) this.getParentEntity());
if (null != linkErrorCode) {
AttributeFieldError error = new AttributeFieldError(this, linkErrorCode, tracer);
AttributeFieldError error = new AttributeFieldError(this, linkErrorCode, textTracer);
error.setMessage("Invalid link - page " + symbLink.getPageDest()
+ " - content " + symbLink.getContentDest() + " - Error code " + linkErrorCode);
errors.add(error);
@@ -37,7 +37,7 @@
* Classe manager degli attributi tipo Hypertext.
* @author E.Santoboni
*/
public class HypertextAttributeManager extends com.agiletec.apsadmin.system.entity.attribute.manager.HypertextAttributeManager {
public class HypertextAttributeManager extends com.agiletec.apsadmin.system.entity.attribute.manager.TextAttributeManager {

@Deprecated
protected void checkSingleAttribute(ActionSupport action, AttributeInterface attribute, AttributeTracer tracer, IApsEntity entity) {
@@ -23,7 +23,6 @@
import com.agiletec.aps.system.common.entity.model.FieldError;
import com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute;
import com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute;
import com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute;
import com.agiletec.aps.system.services.group.Group;
import com.agiletec.plugins.jacms.aps.system.JacmsSystemConstants;
import com.agiletec.plugins.jacms.aps.system.services.content.model.Content;
@@ -128,8 +127,6 @@ public void testValidate_4() throws Throwable {
+ "Ripeto, Titolo che supera la lunghezza massima di cento caratteri";
try {
Content content = this.createNewVoid("RAH", "descr", Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
ITextAttribute emailAttribute = (ITextAttribute) content.getAttribute("email");
emailAttribute.setText("joe.brown@company.com", null);

ITextAttribute textAttribute = (ITextAttribute) content.getAttribute("Titolo");
textAttribute.setText(shortTitle, "it");
@@ -307,6 +307,7 @@ public void testValidate_5() throws Throwable {

ActionSupport action = this.getAction();
Map<String, List<String>> fieldErros = action.getFieldErrors();

assertEquals(1, fieldErros.size());

List<String> titleItFieldErrors = fieldErros.get("it_Titolo");