1 | package sloot; |
---|
2 | |
---|
3 | import com.ten60.netkernel.urii.*; |
---|
4 | import com.ten60.netkernel.urii.aspect.IAspectBoolean; |
---|
5 | import org.ten60.netkernel.xml.xahelper.*; |
---|
6 | import org.ten60.netkernel.xml.xda.*; |
---|
7 | import org.ten60.netkernel.xml.representation.*; |
---|
8 | |
---|
9 | |
---|
10 | import org.ten60.netkernel.layer1.nkf.*; |
---|
11 | import org.ten60.netkernel.layer1.nkf.impl.*; |
---|
12 | import org.ten60.netkernel.layer1.representation.*; |
---|
13 | import org.ten60.netkernel.layer1.meta.DependencyMeta; |
---|
14 | |
---|
15 | import java.util.*; |
---|
16 | import java.util.regex.*; |
---|
17 | import java.net.URI; |
---|
18 | |
---|
19 | import org.w3c.dom.*; |
---|
20 | import javax.xml.parsers.DocumentBuilderFactory; |
---|
21 | import javax.xml.transform.*; |
---|
22 | import javax.xml.transform.dom.DOMSource; |
---|
23 | import javax.xml.transform.stream.StreamResult; |
---|
24 | |
---|
25 | import net.sf.saxon.s9api.*; |
---|
26 | |
---|
27 | /** |
---|
28 | * Evaluate the DBX guide document. |
---|
29 | * @author maw |
---|
30 | */ |
---|
31 | public class DBXEngine extends NKFAccessorImpl { |
---|
32 | |
---|
33 | /** Creates a new instance of the DBX Engine */ |
---|
34 | public DBXEngine() { |
---|
35 | super(4, SAFE_FOR_CONCURRENT_USE, INKFRequestReadOnly.RQT_SOURCE); |
---|
36 | } |
---|
37 | |
---|
38 | public void processRequest(INKFConvenienceHelper nk) throws Exception { |
---|
39 | sloot.dbx.Engine engine = new sloot.dbx.Engine(); |
---|
40 | |
---|
41 | // get the NK request |
---|
42 | INKFRequestReadOnly nkreq = nk.getThisRequest(); |
---|
43 | |
---|
44 | // set NK context |
---|
45 | engine.setNKContext(nk); |
---|
46 | |
---|
47 | // determine debug flag |
---|
48 | boolean debug = false; |
---|
49 | if (nkreq.argumentExists("debug")) { |
---|
50 | String val = "" + debug; |
---|
51 | String paramURI = nkreq.getArgument("debug"); |
---|
52 | if (paramURI.startsWith("data:text/plain,")) |
---|
53 | val = paramURI.substring(("data:text/plain,").length(),paramURI.length()); |
---|
54 | else { |
---|
55 | IXAspect param = (IXAspect)nk.sourceAspect(paramURI, IXAspect.class); |
---|
56 | val = param.getXDA().getText(".",true); |
---|
57 | } |
---|
58 | debug = (val.equals("true") || val.equals("t")); |
---|
59 | } |
---|
60 | engine.setDebug(debug); |
---|
61 | |
---|
62 | // determine trace flag |
---|
63 | boolean trace = false; |
---|
64 | if (nkreq.argumentExists("trace")) { |
---|
65 | String val = "" + trace; |
---|
66 | String paramURI = nkreq.getArgument("trace"); |
---|
67 | if (paramURI.startsWith("data:text/plain,")) |
---|
68 | val = paramURI.substring(("data:text/plain,").length(),paramURI.length()); |
---|
69 | else { |
---|
70 | IXAspect param = (IXAspect)nk.sourceAspect(paramURI, IXAspect.class); |
---|
71 | val = param.getXDA().getText(".",true); |
---|
72 | } |
---|
73 | trace = (val.equals("true") || val.equals("t")); |
---|
74 | } |
---|
75 | engine.setTrace(trace); |
---|
76 | |
---|
77 | // determine strict flag |
---|
78 | boolean strict = true; |
---|
79 | if (nkreq.argumentExists("strict")) { |
---|
80 | String val = "" + strict; |
---|
81 | String paramURI = nkreq.getArgument("strict"); |
---|
82 | if (paramURI.startsWith("data:text/plain,")) |
---|
83 | val = paramURI.substring(("data:text/plain,").length(),paramURI.length()); |
---|
84 | else { |
---|
85 | IXAspect param = (IXAspect)nk.sourceAspect(paramURI, IXAspect.class); |
---|
86 | val = param.getXDA().getText(".",true); |
---|
87 | } |
---|
88 | strict = (val.equals("true") || val.equals("t")); |
---|
89 | } |
---|
90 | engine.setStrict(strict); |
---|
91 | |
---|
92 | // determine cache directory |
---|
93 | String cache = "file:///tmp/sloot-dbx-cache"; |
---|
94 | if (nkreq.argumentExists("cache")) { |
---|
95 | String val = "" + cache; |
---|
96 | String paramURI = nkreq.getArgument("cache"); |
---|
97 | if (paramURI.startsWith("data:text/plain,")) |
---|
98 | val = paramURI.substring(("data:text/plain,").length(),paramURI.length()); |
---|
99 | else { |
---|
100 | IXAspect param = (IXAspect)nk.sourceAspect(paramURI, IXAspect.class); |
---|
101 | val = param.getXDA().getText(".",true); |
---|
102 | } |
---|
103 | cache = (val.equals("")?cache:val); |
---|
104 | } |
---|
105 | engine.setCacheDirectory(cache); |
---|
106 | |
---|
107 | // get the DBX guide document |
---|
108 | IXAspect optxa = (IXAspect)nk.sourceAspect("this:param:operator", IXAspect.class); |
---|
109 | engine.setGuide(optxa.getReadOnlyDocument()); |
---|
110 | |
---|
111 | IURAspect aspect = engine.run(); |
---|
112 | nk.createResponseFrom(aspect).setMimeType("application/xml"); |
---|
113 | } |
---|
114 | } |
---|