001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: ValidationFormatter.java 3669 2007-02-26 13:51:23Z gbevin $
007: */
008: package com.uwyn.rife.site;
009:
010: import java.util.Collection;
011:
012: import com.uwyn.rife.template.Template;
013:
014: /**
015: * Since this entire class has been deprecated it will not even be
016: * tested anymore, use {@link ValidationBuilder} now instead.
017: *
018: * @deprecated
019: */
020: ///CLOVER:OFF
021: public abstract class ValidationFormatter {
022: /**
023: * @deprecated
024: */
025: public static final String DEFAULT_ERROR_MESSAGE_ID = "error_message";
026: /**
027: * @deprecated
028: */
029: public static final String DEFAULT_ERROR_LINE_ID = "error_line";
030: /**
031: * @deprecated
032: */
033: public static final String DEFAULT_ERROR_CONTENT_ID = "error_content";
034: /**
035: * @deprecated
036: */
037: public static final String DEFAULT_ERROR_AREA_ID = "error_area";
038:
039: /**
040: * @deprecated
041: */
042: public static void setValidationErrors(Template template,
043: Collection<ValidationError> errors) {
044: setValidationErrors(template, errors, DEFAULT_ERROR_MESSAGE_ID,
045: DEFAULT_ERROR_LINE_ID, DEFAULT_ERROR_CONTENT_ID,
046: DEFAULT_ERROR_AREA_ID);
047: }
048:
049: /**
050: * @deprecated
051: */
052: public static void setValidationErrors(Template template,
053: Collection<ValidationError> errors, String errorMessageId,
054: String errorLineId, String errorContentId,
055: String errorAreaId) {
056: if (null == template || null == errors) {
057: return;
058: }
059:
060: if (null == errorMessageId)
061: throw new IllegalArgumentException(
062: "errorMessageId can't be null.");
063: if (null == errorLineId)
064: throw new IllegalArgumentException(
065: "errorLineId can't be null.");
066: if (null == errorContentId)
067: throw new IllegalArgumentException(
068: "errorContentId can't be null.");
069: if (null == errorAreaId)
070: throw new IllegalArgumentException(
071: "errorAreaId can't be null.");
072:
073: if (!template.hasValueId(errorMessageId))
074: throw new IllegalArgumentException(
075: "Missing template value '" + errorMessageId + "'.");
076: if (!template.hasValueId(errorContentId))
077: throw new IllegalArgumentException(
078: "Missing template value '" + errorContentId + "'.");
079: if (!template.hasValueId(errorAreaId))
080: throw new IllegalArgumentException(
081: "Missing template value '" + errorAreaId + "'.");
082: if (!template.hasBlock(errorLineId))
083: throw new IllegalArgumentException(
084: "Missing template block '" + errorLineId + "'.");
085: if (!template.hasBlock(errorAreaId))
086: throw new IllegalArgumentException(
087: "Missing template block '" + errorAreaId + "'.");
088:
089: String error_block_name;
090: for (ValidationError error : errors) {
091: error_block_name = error.getIdentifier() + ":"
092: + error.getSubject();
093: if (template.hasBlock(error_block_name)) {
094: template.setBlock(errorMessageId, error_block_name);
095: } else {
096: template.setValue(errorMessageId, error_block_name);
097: }
098: template.appendBlock(errorContentId, errorLineId);
099: }
100:
101: template.setBlock(errorAreaId, errorAreaId);
102: }
103:
104: /**
105: * @deprecated
106: */
107: public static void setErrorArea(Template template, String content) {
108: setErrorArea(template, content, DEFAULT_ERROR_MESSAGE_ID,
109: DEFAULT_ERROR_LINE_ID, DEFAULT_ERROR_CONTENT_ID,
110: DEFAULT_ERROR_AREA_ID);
111: }
112:
113: /**
114: * @deprecated
115: */
116: public static void setErrorArea(Template template, String content,
117: String errorMessageId, String errorLineId,
118: String errorContentId, String errorAreaId) {
119: if (null == template || null == content) {
120: return;
121: }
122:
123: if (null == errorMessageId)
124: throw new IllegalArgumentException(
125: "errorMessageId can't be null.");
126: if (null == errorLineId)
127: throw new IllegalArgumentException(
128: "errorLineId can't be null.");
129: if (null == errorContentId)
130: throw new IllegalArgumentException(
131: "errorContentId can't be null.");
132: if (null == errorAreaId)
133: throw new IllegalArgumentException(
134: "errorAreaId can't be null.");
135:
136: if (!template.hasValueId(errorMessageId))
137: throw new IllegalArgumentException(
138: "Missing template value '" + errorMessageId + "'.");
139: if (!template.hasValueId(errorContentId))
140: throw new IllegalArgumentException(
141: "Missing template value '" + errorContentId + "'.");
142: if (!template.hasValueId(errorAreaId))
143: throw new IllegalArgumentException(
144: "Missing template value '" + errorAreaId + "'.");
145: if (!template.hasBlock(errorLineId))
146: throw new IllegalArgumentException(
147: "Missing template block '" + errorLineId + "'.");
148: if (!template.hasBlock(errorAreaId))
149: throw new IllegalArgumentException(
150: "Missing template block '" + errorAreaId + "'.");
151:
152: template.setValue(errorMessageId, content);
153: template.setBlock(errorContentId, errorLineId);
154: template.setBlock(errorAreaId, errorAreaId);
155: }
156:
157: /**
158: * @deprecated
159: */
160: public static void highlightInvalidSubjects(Template template,
161: Collection<ValidationError> errors,
162: String highlightValuePrefix, String highlightBlockId) {
163: if (null == template || null == errors) {
164: return;
165: }
166:
167: if (null == highlightValuePrefix)
168: throw new IllegalArgumentException(
169: "highlightValuePrefix can't be null.");
170: if (null == highlightBlockId)
171: throw new IllegalArgumentException(
172: "highlightBlockId can't be null.");
173:
174: // highlight the validation erors
175: String value_id;
176: for (ValidationError validationerror : errors) {
177: value_id = highlightValuePrefix
178: + validationerror.getSubject();
179: if (template.hasValueId(value_id)) {
180: template.setBlock(value_id, highlightBlockId);
181: }
182: }
183: }
184: }
185: ///CLOVER:ON
|