Java Code Examples for com.opensymphony.xwork2.ActionSupport#addFieldError()

The following examples show how to use com.opensymphony.xwork2.ActionSupport#addFieldError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PageSettingsActionAspect.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean checkPath(String alternativePath, ActionSupport action) {
    File file = new File(alternativePath);
    if (file.exists()) {
        if (!file.canRead() || !file.canWrite()) {
            action.addFieldError(PARAM_ROBOT_ALTERNATIVE_PATH_CODE,
                    action.getText("jpseo.error.robotFilePath.file.requiredAuth", new String[]{alternativePath}));
            return false;
        }
    } else {
        File directory = file.getParentFile();
        if (!directory.exists()) {
            action.addFieldError(PARAM_ROBOT_ALTERNATIVE_PATH_CODE,
                    action.getText("jpseo.error.robotFilePath.directory.notExists", new String[]{directory.getAbsolutePath()}));
            return false;
        } else if (!directory.canRead() || !directory.canWrite()) {
            action.addFieldError(PARAM_ROBOT_ALTERNATIVE_PATH_CODE,
                    action.getText("jpseo.error.robotFilePath.directory.requiredAuth", new String[]{directory.getAbsolutePath()}));
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: ContentActionHelperAspect.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void checkFriendlyCode(String text, Lang currentLang, String attributeName, String msgPrefix, String contentId, ActionSupport action) {
	String friendlyCode = FriendlyCodeGenerator.generateFriendlyCode(text);
	if (null != friendlyCode) {
		FriendlyCodeVO fcVO = this.getSeoMappingManager().getReference(friendlyCode);
		if (null != fcVO && (contentId==null || !contentId.equals(fcVO.getContentId()))) {
			String errorMsg = null;
			if (currentLang == null) {
				errorMsg = action.getText("jpseo.error.content.friendlyCode.alreadyInUse", new String[] { friendlyCode });
			} else {
				errorMsg = action.getText("jpseo.error.content.friendlyCodeForLang.alreadyInUse", new String[] { friendlyCode, currentLang.getDescr() });
			}
			String fcUtilizer = null;
			if (fcVO.getPageCode() != null) {
				fcUtilizer = action.getText("jpseo.error.content.friendlyCode.utilizer.page", new String[] { fcVO.getPageCode() });
			} else {
				fcUtilizer = action.getText("jpseo.error.content.friendlyCode.utilizer.content", new String[] { fcVO.getContentId() });
			}
			action.addFieldError(attributeName, msgPrefix + " " + errorMsg + " " + fcUtilizer);
		}
	}
}
 
Example 3
Source File: DataObjectActionHelper.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void scanEntity(IApsEntity entity, ActionSupport action) {
    DataObject dataObject = (DataObject) entity;
    if (null == dataObject) {
        _logger.error("Null DataObject");
        return;
    }
    String descr = dataObject.getDescription();
    if (descr == null || descr.length() == 0) {
        action.addFieldError("descr", action.getText("error.dataobject.descr.required"));
    } else {
        int maxLength = 250;
        if (descr.length() > maxLength) {
            String[] args = {String.valueOf(maxLength)};
            action.addFieldError("descr", action.getText("error.dataobject.descr.wrongMaxLength", args));
        }
        if (!descr.matches("([^\"])+")) {
            action.addFieldError("descr", action.getText("error.dataobject.descr.wrongCharacters"));
        }
    }
    if (null == dataObject.getId() && (dataObject.getMainGroup() == null || dataObject.getMainGroup().length() == 0)) {
        action.addFieldError("mainGroup", action.getText("error.dataobject.mainGroup.required"));
    }
    try {
        super.scanEntity(dataObject, action);
    } catch (Throwable t) {
        _logger.error("DataObjectActionHelper - scanEntity", t);
        throw new RuntimeException("Error checking entity", t);
    }
}
 
Example 4
Source File: EntityActionHelper.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void scanEntity(IApsEntity currentEntity, ActionSupport action) {
	try {
		List<AttributeInterface> attributes = currentEntity.getAttributeList();
		for (int i = 0; i < attributes.size(); i++) {
			AttributeInterface entityAttribute = attributes.get(i);
			if (entityAttribute.isActive()) {
				List<AttributeFieldError> errors = entityAttribute.validate(new AttributeTracer());
				if (null != errors && errors.size() > 0) {
					for (int j = 0; j < errors.size(); j++) {
						AttributeFieldError attributeFieldError = errors.get(j);
						AttributeTracer tracer = attributeFieldError.getTracer();
						AttributeInterface attribute = attributeFieldError.getAttribute();
						String messageAttributePositionPrefix = this.createErrorMessageAttributePositionPrefix(action, attribute, tracer);
						AttributeManagerInterface attributeManager = this.getManager(attribute);
						String errorMessage = attributeManager.getErrorMessage(attributeFieldError, action);
						String formFieldName = tracer.getFormFieldName(attributeFieldError.getAttribute());
						action.addFieldError(formFieldName, messageAttributePositionPrefix + " " + errorMessage);
					}
				}
			}
		}
	} catch (Throwable t) {
		_logger.error("Error scanning Entity", t);
		throw new RuntimeException("Error scanning Entity", t);
	}
}
 
Example 5
Source File: ContentPageValidator.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void checkContent(ActionSupport action, String contentId) throws ApsSystemException {
    if (StringUtils.isNotBlank(contentId)) {
        Content content = this.getContentManager().loadContent(contentId, true);
        if (null == content || !content.isOnLine()) {
            List<String> args = new ArrayList<>();
            args.add(null == content ? contentId : content.getDescription());
            action.addFieldError("extraGroups", action.getText("error.page.setOnlineContent.ref.offline", args));
        }
    }
}
 
Example 6
Source File: ContentActionHelper.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void scanEntity(IApsEntity entity, ActionSupport action) {
    Content content = (Content) entity;
    if (null == content) {
        logger.error("Null Content");
        return;
    }
    String descr = content.getDescription();
    if (descr == null || descr.length() == 0) {
        action.addFieldError(DESCR, action.getText("error.content.descr.required"));
    } else {
        int maxLength = 250;
        if (descr.length() > maxLength) {
            String[] args = {String.valueOf(maxLength)};
            action.addFieldError(DESCR, action.getText("error.content.descr.wrongMaxLength", args));
        }
        if (!descr.matches("([^\"])+")) {
            action.addFieldError(DESCR, action.getText("error.content.descr.wrongCharacters"));
        }
    }
    if (null == content.getId() && (content.getMainGroup() == null || content.getMainGroup().length() == 0)) {
        action.addFieldError(MAIN_GROUP, action.getText("error.content.mainGroup.required"));
    }
    try {
        this.scanReferences(content, action);
        super.scanEntity(content, action);
    } catch (Throwable t) {
        logger.error("ContentActionHelper - scanEntity", t);
        throw new RuntimeException("Error checking entity", t);
    }
}