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:
14: /**
15: * @author AYegorov
16: *
17: * To change the template for this generated type comment go to
18: * Window>Preferences>Java>Code Generation>Code and Comments
19: */
20: public class TextPart extends AbstractText {
21:
22: /**
23: * @param id
24: */
25: public TextPart(String id) {
26: super (id);
27: // TODO Auto-generated constructor stub
28: }
29:
30: /**
31: * @param id
32: * @param properties
33: */
34: public TextPart(String id, HashMap properties) {
35: super (id, properties);
36: // TODO Auto-generated constructor stub
37: }
38:
39: /* (non-Javadoc)
40: * @see org.xdev.base.transaction.AbstractTransactionResult#getValue()
41: */
42: public Object processText(String text) throws Exception {
43: XSSLReturn start = (XSSLReturn) this .getElement(0);
44:
45: int s = -1;
46: int e = -1;
47:
48: if (this .getCount() > 1) {
49: XSSLReturn end = (XSSLReturn) this .getElement(1);
50:
51: e = this .evaluateIndex(end, text);
52: }
53:
54: s = this .evaluateIndex(start, text);
55:
56: text = text.substring(e == -1 ? 0 : s, e == -1 ? s : e);
57:
58: return text;
59: }
60:
61: protected int evaluateIndex(XSSLReturn val, String text)
62: throws Exception {
63:
64: int index = -1;
65:
66: if (val.execute(this )) {
67: Object object = val.getObjectValue();
68:
69: if (object != null) {
70:
71: String objectString = object.toString();
72:
73: try {
74: if (!val.getBooleanProperty("non-numeric")) {
75: index = Integer.parseInt(objectString);
76: }
77: } catch (Exception ex) {
78: this .logDebug(ex);
79: }
80:
81: if (index == -1) {
82: index = text.indexOf(objectString);
83: }
84:
85: }
86: }
87:
88: return index;
89: }
90:
91: }
|