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.text;
008:
009: import java.util.HashMap;
010:
011: import org.xdev.base.xssl.XSSLAction;
012: import org.xdev.base.xssl.XSSLActionIterator;
013: import org.xdev.base.xssl.XSSLReturn;
014: import org.xdev.base.xssl.XText;
015:
016: import org.xdev.base.xssl.manage.ITransactionFinalizable;
017:
018: import org.xdev.base.core.compiler.AXCompiler;
019: import org.xdev.base.util.Tools;
020:
021: /**
022: * @author AYegorov
023: *
024: * To change the template for this generated type comment go to
025: * Window>Preferences>Java>Code Generation>Code and Comments
026: */
027: public class TextAppend extends XSSLActionIterator implements
028: ITransactionFinalizable {
029: protected StringBuffer buffer = null;
030:
031: /**
032: * @param id
033: */
034: public TextAppend(String id) {
035: super (id);
036: // TODO Auto-generated constructor stub
037: }
038:
039: /**
040: * @param id
041: * @param properties
042: */
043: public TextAppend(String id, HashMap properties) {
044: super (id, properties);
045: // TODO Auto-generated constructor stub
046: }
047:
048: protected void invoke(XSSLAction component) throws Exception {
049: if (component instanceof XSSLReturn) {
050: this .append((XSSLReturn) component, this .buffer);
051: }
052: }
053:
054: protected void append(XSSLReturn element, StringBuffer buffer)
055: throws Exception {
056: Object v = element.getObjectValue();
057:
058: this .logDebug("Appending value: " + v);
059:
060: if (v != null || !this .getBooleanProperty("allow-null")
061: && this .hasProperty("allow-null")) {
062: buffer.append(Tools.replaceString(Tools.replaceString(Tools
063: .replaceString(this .applyModifications(v)
064: .toString(), "\\t", "\t"), "\\n", "\n"),
065: "\\s", " "));
066: }
067:
068: element = null;
069: }
070:
071: protected Object applyModifications(Object value) {
072: return value;
073: }
074:
075: public Object getObjectValue() {
076:
077: String response = "";
078:
079: if (this .buffer != null) {
080: response = this .buffer.toString();
081: }
082:
083: StringBuffer result = new StringBuffer();
084:
085: try {
086:
087: XText.compileText(response, result, AXCompiler
088: .getInstance(), this );
089:
090: response = result.toString();
091:
092: result.setLength(0);
093:
094: response = Tools.replaceString(Tools.replaceString(Tools
095: .replaceString(response, "\\n", ""), "\\t", ""),
096: "\\s", " ");
097:
098: result.append(response);
099: } catch (Exception ex) {
100: this .logError(ex);
101: }
102:
103: this .logDebug("Returning appended results: " + result);
104:
105: return result;
106: }
107:
108: /* (non-Javadoc)
109: * @see org.xdev.base.transaction.AbstractTransactionResult#set()
110: */
111: protected void set() throws Exception {
112:
113: Object ref = this .getEvaluatedReference();
114:
115: this .logDebug("Buffer reference: " + ref);
116:
117: if (this .buffer == null
118: && (this .buffer = (StringBuffer) ref) == null) {
119: this .buffer = new StringBuffer();
120: }
121:
122: if (!this .getBooleanProperty("persist")) {
123: buffer.setLength(0);
124: }
125:
126: this .logDebug("Buffer created: " + this .buffer);
127:
128: }
129:
130: /* (non-Javadoc)
131: * @see org.xdev.base.xssl.manage.ITransactionFinalizable#doFinalize()
132: */
133: public void doFinalize() throws Exception {
134: if (buffer != null) {
135: buffer.setLength(0);
136: }
137:
138: }
139:
140: }
|