Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
themeEclipse
public class TitleWorkflowActionConstraint extends SimpleServiceComponent implements WorkflowActionConstraint {

	private static final Logger LOG = Logger.getLogger(TitleWorkflowActionConstraint.class.getName());

	private static final String TITLEKEY = "pagemetadata.constraint.title";

	private static final Map<Locale, String> TITLE_MESSAGES = new HashMap<Locale, String>();

	private static final Map<Locale, String> VALIDATION_MESSAGES = new HashMap<Locale, String>();

	static {
		Locale localeNL = new Locale("nl", "NL"); 
		ResourceBundle bundle_nl = ResourceBundle.getBundle("messages/messages", new Locale("nl", "NL"));
		ResourceBundle bundle_en = ResourceBundle.getBundle("messages/messages", Locale.US);

		TITLE_MESSAGES.put(localeNL, bundle_nl.getString(TITLEKEY));
		TITLE_MESSAGES.put(Locale.US, bundle_en.getString(TITLEKEY));

		VALIDATION_MESSAGES.put(localeNL, bundle_nl.getString(TITLEKEY));
		VALIDATION_MESSAGES.put(Locale.US, bundle_en.getString(TITLEKEY));
	}

	@Override
	public Map<Locale, String> getTitleMessages() {
		return TITLE_MESSAGES;
	}

@Override
	public String getIdentifier() {
		return WCBConstants.BUNDLE_ID + ".titleWorkflowActionConstraint";
	}

	@Override
	public WorkflowActionConstraintResult validate(final WorkflowEnabled workflowEnabled) {
		final boolean isValid;

		// Validate
		final String title;
		if (workflowEnabled instanceof PageVersion) {
			title = ((PageVersion) workflowEnabled).getTitle();
		} else if (workflowEnabled instanceof MediaItemVersion) {
			title = ((MediaItemVersion) workflowEnabled).getTitle();
		} else {
			title = null;
		}

		isValid = !"".equals(title);
		return new WorkflowActionConstraintResult() {

			@Override
				public String getIdentifier() {
					return TitleWorkflowActionConstraint.this.getIdentifier();
			}

			@Override
			public Map<Locale, String> getMessages() {
				if (isValid) {
					return null;
				} else {
					return VALIDATION_MESSAGES;
				}
			}

			@Override
			public boolean isValid() {
				return isValid;
			}
		}
	}

 

 

Back to Top