001: /*
002: * Created on Jul 14, 2003
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package org.xdev.base.xssl;
008:
009: import java.util.ArrayList;
010: import java.util.HashMap;
011: import java.util.Iterator;
012:
013: import org.xdev.base.util.ServerUtilities;
014: import org.xdev.base.util.Tools;
015: import org.xdev.base.xssl.text.TextAppend;
016:
017: /**
018: * @author AYegorov
019: *
020: * To change the template for this generated type comment go to
021: * Window>Preferences>Java>Code Generation>Code and Comments
022: */
023: public final class XContainer extends TextAppend {
024: public static final String TRANSACTION_CONTAINER_TAG_NAME = "container";
025:
026: private String openTag = "";
027: private String closeTag = "";
028:
029: private HashMap attributes = new HashMap();
030:
031: /**
032: * @param id
033: */
034: public XContainer(String id) {
035: super (id);
036: // TODO Auto-generated constructor stub
037: }
038:
039: /**
040: * @param id
041: * @param properties
042: */
043: public XContainer(String id, HashMap properties) {
044: super (id, properties);
045: this .attributes = (HashMap) properties.clone();
046: }
047:
048: private String buildOpenTag(String id, HashMap attributes) {
049: StringBuffer buffer = new StringBuffer();
050: buffer.append("<").append(id);
051: if (attributes != null && attributes.size() > 0) {
052: Iterator iter = attributes.keySet().iterator();
053: String name = null;
054: Object value = null;
055: while (iter.hasNext()) {
056: name = (String) iter.next();
057: if (name != null && !name.startsWith("@")
058: && !name.endsWith("@") && !name.startsWith("$")) {
059: value = attributes.get(name);
060: if (value != null && !"".equals(value)) {
061: value = this .resolveKeyword(value);
062:
063: value = (value != null ? value.toString() : "");
064:
065: try {
066: buffer.append(" ").append(name).append("=")
067: .append("\"").append(
068: ServerUtilities
069: .escapeXml(value))
070: .append("\"");
071: } catch (Exception ex) {
072: this .log(ex);
073: }
074: value = null;
075: }
076: }
077: name = null;
078: }
079: }
080:
081: return buffer.append(">").toString();
082: }
083:
084: private String buildCloseTag(String id) {
085: StringBuffer buffer = new StringBuffer();
086:
087: return buffer.append("</").append(id).append(">").toString();
088: }
089:
090: /* (non-Javadoc)
091: * @see org.xdev.base.templates.TemplateElementIterator#invoke(org.xdev.base.templates.TemplateComponent)
092: */
093: /*protected void invoke(XSSLAction component) throws Exception {
094: if (component instanceof XSSLReturn) {
095: Object value = ((XSSLReturn)component).getValue();
096:
097: if (value != null) {
098: this.buffer.append(value);
099: }
100: }
101: }
102:
103: protected void set() throws Exception{
104: this.buffer = new StringBuffer();
105: }*/
106:
107: protected void invoke() throws Exception {
108: super .invoke();
109: }
110:
111: /*public Object getValue(){
112: return this.buffer.toString();
113: }*/
114:
115: /* (non-Javadoc)
116: * @see org.xdev.base.transaction.AbstractTransaction#setTagName()
117: */
118: protected String setTagName() {
119: return XContainer.TRANSACTION_CONTAINER_TAG_NAME;
120: }
121:
122: public void setOpenTag(String tag) {
123: this .openTag = tag;
124: }
125:
126: public void setCloseTag(String tag) {
127: this .closeTag = tag;
128: }
129:
130: public Object getObjectValue() {
131:
132: java.util.List children = this .getRoot().getTemporaryBind(
133: this .getName());
134:
135: if (children != null && children.size() > 0) {
136:
137: int size = children.size();
138:
139: XSSLComponent child = null;
140:
141: ArrayList returns = new ArrayList();
142:
143: for (int i = 0; i < size; i++) {
144:
145: child = (XSSLComponent) children.get(i);
146:
147: if (child instanceof XSSLAction) {
148:
149: try {
150: ((XSSLAction) child).execute((XSSLAction) this
151: .getParentComponent());
152:
153: if (child instanceof XSSLReturn) {
154: returns.add(((XSSLReturn) child)
155: .getObjectValue());
156: }
157: } catch (Exception ex) {
158: this .logError(ex);
159: }
160: }
161: }
162:
163: return returns.size() == 1 ? returns.get(0) : returns;
164:
165: } else {
166: StringBuffer buffer = new StringBuffer();
167:
168: buffer.append(this.buildOpenTag(this.getId(),
169: this.attributes));
170:
171: buffer.append(super.getObjectValue());
172:
173: buffer.append(this.buildCloseTag(this.getId()));
174:
175: return buffer.toString();
176: }
177: }
178:
179: }
|