01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.action;
19:
20: import java.io.IOException;
21: import java.io.StringReader;
22: import java.util.Iterator;
23:
24: import javax.xml.parsers.DocumentBuilder;
25: import javax.xml.parsers.DocumentBuilderFactory;
26:
27: import org.w3c.dom.Node;
28: import org.xml.sax.InputSource;
29:
30: import de.finix.contelligent.CallData;
31: import de.finix.contelligent.DomComponent;
32: import de.finix.contelligent.exception.ContelligentException;
33:
34: public class OrderedErrorMessages extends StoredObject implements
35: Constants, DomComponent {
36:
37: private DocumentBuilderFactory fac;
38:
39: public OrderedErrorMessages() {
40: super ();
41: fac = DocumentBuilderFactory.newInstance();
42: }
43:
44: public String getString(CallData callData)
45: throws ContelligentException, IOException {
46: ErrorMessageList list = (ErrorMessageList) getObject(callData);
47:
48: StringBuffer buffer = new StringBuffer(128);
49: buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
50: buffer.append("<errors>");
51:
52: if (list != null) {
53: Iterator iterator = list.getMessages();
54: int count = 1;
55: while (iterator.hasNext()) {
56: buffer.append("<error number=\"");
57: buffer.append(count++);
58: buffer.append("\" text=\"");
59: buffer.append(iterator.next());
60: buffer.append("\"/>\n");
61: }
62: }
63: buffer.append("</errors>");
64: return buffer.toString();
65: }
66:
67: public Node getNode(CallData callData) throws ContelligentException {
68: String value = null;
69:
70: try {
71: DocumentBuilder builder = fac.newDocumentBuilder();
72: value = renderComponent(this , callData);
73:
74: return builder.parse(new InputSource(
75: new StringReader(value)));
76: } catch (org.xml.sax.SAXException se) {
77: throw new ContelligentException(
78: "problems with parsing the value " + value, se);
79: } catch (java.io.IOException ioe) {
80: throw new ContelligentException(
81: "io problems with a bad desease ", ioe);
82: } catch (javax.xml.parsers.ParserConfigurationException pce) {
83: throw new ContelligentException(
84: "parser configuration problems", pce);
85: }
86: }
87:
88: protected String getSessionStorageKey() {
89: return ORDERED_ERROR_STORE;
90: }
91:
92: protected String getRequestStorageKey() {
93: return ORDERED_ERROR_STORE;
94: }
95:
96: }
|