01: package nl.hippo.cms.wizard.components;
02:
03: import nl.hippo.cms.wizard.Constants;
04: import nl.hippo.cms.wizard.WizardResult;
05: import nl.hippo.cms.wizard.i18n.I18NHelper;
06:
07: import org.springframework.web.context.WebApplicationContext;
08: import org.xml.sax.SAXException;
09:
10: public abstract class AbstractComponent implements Component {
11: private String id;
12: private String label;
13: private String labelCatalogue;
14: private String path;
15: private boolean skip = false;
16: private boolean lowercase = false;
17:
18: public void configure(Configuration config) throws Exception {
19: if (config != null) {
20: String id = config.get(Constants.ID_ATTRIBUTE_NAME);
21: if (id == null || id.equals(""))
22: throw new Exception("Component @id is required");
23: this .id = id;
24:
25: this .path = "";
26: this .label = I18NHelper.idToKey(id);
27: this .labelCatalogue = Constants.DEFAULT_LABEL_CATALOGUE;
28:
29: String path = config.get(Constants.PATH_ATTRIBUTE_NAME);
30: if (path != null) {
31: if (path.endsWith(Constants.URI_DELIMITER)
32: && !path.equals(Constants.URI_DELIMITER)) {
33: path = path.substring(0, path
34: .lastIndexOf(Constants.URI_DELIMITER));
35: }
36: this .path = path;
37: }
38: String label = config.get(Constants.LABEL_ATTRIBUTE_NAME);
39: if (label != null && !label.equals("")) {
40: int index = label.indexOf(":");
41: if (index > 0) {
42: this .labelCatalogue = label.substring(0, index);
43: this .label = label.substring(index + 1);
44: } else {
45: this .label = label;
46: }
47: }
48: }
49: }
50:
51: //used for checking configuration values of child components
52: public void initialize() throws SAXException {
53: }
54:
55: public void fillResult(WizardResult result,
56: WebApplicationContext context) throws Exception {
57: if (!skip && !getPath().equals("")) {
58: if (lowercase) {
59: result.addLowerCasePath(getPath().toLowerCase());
60: } else {
61: result.addPath(getPath());
62: }
63: }
64: result.addId(getId());
65: }
66:
67: public String getPath() {
68: return path;
69: }
70:
71: public String getId() {
72: return id;
73: }
74:
75: public String getLabel() {
76: return label;
77: }
78:
79: public String getLabelCatalogue() {
80: return labelCatalogue;
81: }
82:
83: public void skipPath() {
84: skip = true;
85: }
86:
87: public void lowerCasePath() {
88: lowercase = true;
89: }
90:
91: public void reset() {
92: }
93: }
|