01: /*
02: * Created on Aug 5, 2003
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;
08:
09: import java.util.ArrayList;
10: import java.util.HashMap;
11:
12: import org.xdev.base.xssl.*;
13: import org.xdev.base.util.*;
14:
15: /**
16: * @author AYegorov
17: *
18: * To change the template for this generated type comment go to
19: * Window>Preferences>Java>Code Generation>Code and Comments
20: */
21: public class TextReplace extends AbstractText {
22:
23: /**
24: * @param id
25: */
26: public TextReplace(String id) {
27: super (id);
28: // TODO Auto-generated constructor stub
29: }
30:
31: /**
32: * @param id
33: * @param properties
34: */
35: public TextReplace(String id, HashMap properties) {
36: super (id, properties);
37: // TODO Auto-generated constructor stub
38: }
39:
40: /* (non-Javadoc)
41: * @see org.xdev.base.transaction.AbstractTransactionResult#getValue()
42: */
43: public Object processText(String text) throws Exception {
44: String v = "";
45:
46: int index = 0;
47:
48: if (this .getReferenceId() == null
49: && (text == null || "".equals(text))) {
50: XSSLReturn textElm = ((XSSLReturn) this .getElement(index++));
51: if (textElm.execute(this )) {
52: text = textElm.getObjectValue().toString();
53: }
54: }
55:
56: XSSLReturn what = (XSSLReturn) this .getElement(index++);
57: XSSLReturn with = this .getCount() > index ? (XSSLReturn) this
58: .getElement(index) : null;
59:
60: if (what.execute(this ) && (with == null || with.execute(this ))) {
61: Object whatObject = what.getObjectValue();
62:
63: this .logDebug("Replacee item: " + what + ", " + whatObject);
64:
65: whatObject = (whatObject != null ? whatObject : "");
66:
67: if (with != null) {
68:
69: Object withObject = with.getObjectValue();
70:
71: this .logDebug("Replacement item: " + with + ", "
72: + withObject);
73:
74: withObject = (withObject != null ? withObject : "");
75:
76: v = Tools.replaceString(text, whatObject.toString(),
77: withObject.toString());
78:
79: withObject = null;
80: } else if (text != null && !"".equals(text)) {
81: v = whatObject.toString();
82: } else {
83: v = "";
84: }
85:
86: whatObject = null;
87: }
88: what = null;
89: with = null;
90:
91: return v;
92: }
93:
94: }
|