01: /*
02: * Created on Mar 23, 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;
08:
09: import java.util.HashMap;
10: import java.util.List;
11: import java.util.regex.Matcher;
12: import java.util.regex.Pattern;
13:
14: import org.jdom.Document;
15: import org.jdom.Element;
16: import org.xdev.base.core.BaseSaxBuilder;
17: import org.xdev.base.core.compiler.AXCompiler;
18: import org.xdev.base.util.ServerUtilities;
19: import org.xdev.base.util.Tools;
20:
21: /**
22: * @author AYegorov
23: *
24: * To change the template for this generated type comment go to
25: * Window>Preferences>Java>Code Generation>Code and Comments
26: */
27: public class XCompile extends XSSLObject {
28: /**
29: * @param id
30: */
31: public XCompile(String id) {
32: super (id);
33: // XXX Auto-generated constructor stub
34: }
35:
36: /**
37: * @param id
38: * @param properties
39: */
40: public XCompile(String id, HashMap properties) {
41: super (id, properties);
42: // XXX Auto-generated constructor stub
43: }
44:
45: /* (non-Javadoc)
46: * @see org.xdev.base.xssl.XSSLObject#processObject(java.lang.Object)
47: */
48: protected Object processObject(Object obj) throws Exception {
49: if (obj == null) {
50: XSSLReturn body = (XSSLReturn) this .getElement(0);
51:
52: if (body.execute(this )) {
53: obj = body.getObjectValue();
54: }
55: }
56:
57: this .log("Compiling: " + obj);
58:
59: BaseSaxBuilder builder = new BaseSaxBuilder();
60:
61: AXCompiler compiler = AXCompiler.getInstance();
62:
63: List list = this .getTokenListProperty("escape");
64:
65: int size = list.size();
66:
67: String escaped = null;
68:
69: for (int i = 0; i < size; i++) {
70:
71: escaped = ServerUtilities.escapeXml(list.get(i).toString());
72:
73: obj = Tools.replaceString(obj.toString(), escaped, Tools
74: .replaceString(escaped, "&", "&"));
75: }
76:
77: Document doc = builder.build(obj.toString(), AXCompiler
78: .getTypes());
79:
80: Element root = doc.getRootElement();
81:
82: XSSLAction action = (XSSLAction) compiler.getCompiledComponent(
83: this .getConfig(), root, this , (XSSLAction) this
84: .getRoot(), this .getRulePath());
85:
86: action.setConfig(this .getConfig());
87:
88: if (action.execute(this ) && action instanceof XSSLReturn) {
89:
90: obj = ((XSSLReturn) action).getObjectValue();
91:
92: }
93:
94: return obj;
95: }
96: }
|