01: /*
02: * Created on Jan 29, 2004
03: *
04: * To change the template for this generated file go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.xdev.base.xssl.text.xml;
08:
09: import java.util.HashMap;
10:
11: import java.io.StringReader;
12:
13: import org.jdom.Attribute;
14: import org.jdom.Document;
15: import org.jdom.Element;
16:
17: import org.jdom.input.SAXBuilder;
18:
19: import org.xdev.base.xssl.XSSLAction;
20: import org.xdev.base.xssl.XSSLReturn;
21:
22: /**
23: * @author AYegorov
24: *
25: * To change the template for this generated type comment go to
26: * Window>Preferences>Java>Code Generation>Code and Comments
27: */
28: public class XmlElement extends AbstractXmlContainer {
29: /**
30: * @param id
31: */
32: public XmlElement(String id) {
33: super (id);
34: // XXX Auto-generated constructor stub
35: }
36:
37: /**
38: * @param id
39: * @param properties
40: */
41: public XmlElement(String id, HashMap properties) {
42: super (id, properties);
43: // XXX Auto-generated constructor stub
44: }
45:
46: /* (non-Javadoc)
47: * @see org.xdev.base.xssl.XSSLActionIterator#invoke(org.xdev.base.xssl.XSSLAction)
48: */
49: protected void invoke(XSSLAction component) throws Exception {
50: if (component instanceof XSSLReturn) {
51: Object obj = ((XSSLReturn) component).getObjectValue();
52:
53: obj = (obj == null ? "" : obj);
54:
55: this .setElementContent(obj, (XSSLReturn) component);
56: }
57: }
58:
59: private void setElementContent(Object obj, XSSLReturn component)
60: throws Exception {
61: if (obj instanceof Attribute) {
62: this .elm.setAttribute((Attribute) obj);
63: } else if (obj instanceof Element) {
64: this .elm.addContent((Element) obj);
65: } else if (obj instanceof Document) {
66: Element root = ((Document) obj).getRootElement();
67:
68: this .elm.addContent(root.detach());
69: } else if (component.hasProperty("attribute-name")) {
70: this .elm.setAttribute(component
71: .getProperty("attribute-name"), obj.toString());
72: } else if (component.getBooleanProperty("is-xml")) {
73: SAXBuilder builder = new SAXBuilder();
74:
75: if (obj != null && !"".equals(obj)) {
76: this .setElementContent(builder.build(new StringReader(
77: obj.toString())), component);
78: }
79: } else {
80: this .elm.setText(obj.toString());
81: }
82: }
83:
84: /* (non-Javadoc)
85: * @see org.xdev.base.xssl.XSSLAction#set()
86: */
87: protected void set() throws Exception {
88: }
89:
90: }
|