1 package org.opensync.engine.xslt.extensions;
2
3 import org.opensync.engine.server.OpenSync;
4 import org.opensync.engine.server.connector.BDConnector;
5 import org.opensync.engine.server.adapter.BDAdapter;
6
7 import net.sf.saxon.expr.XPathContext;
8 import net.sf.saxon.xpath.XPathException;
9 import net.sf.saxon.om.SequenceIterator;
10
11 import javax.xml.parsers.DocumentBuilder;
12 import javax.xml.parsers.DocumentBuilderFactory;
13 import javax.xml.parsers.ParserConfigurationException;
14
15 import org.w3c.dom.*;
16
17 import java.sql.SQLException;
18 import java.sql.Connection;
19
20 public class XSLTExtensionFunction {
21
22
23 /***
24 * Function to get a Xalan NodeList from a Saxon Sequence
25 * @param context
26 * @param nsv
27 * @return NodeList
28 * @throws XPathException
29 */
30
31 protected static NodeList getNodeList(XPathContext context, SequenceIterator nsv) throws XPathException {
32 XPathContext c = context.newContext();
33 c.setCurrentIterator(nsv);
34 int pos = 1;
35 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
36 Document document = null;
37 org.w3c.dom.Element root = null;
38 try {
39 DocumentBuilder builder = factory.newDocumentBuilder();
40 document = builder.newDocument();
41
42 root = (org.w3c.dom.Element) document.createElement("rootElement");
43 document.appendChild(root);
44 while (nsv.hasNext()) {
45 nsv.next();
46 String value = nsv.current().getStringValue();
47 root.appendChild(document.createTextNode(value));
48 }
49 } catch (ParserConfigurationException pce) {
50
51 pce.printStackTrace();
52 }
53 return root.getChildNodes();
54 }
55
56 /***
57 * @param source
58 * @exception SQLException
59 */
60 static protected Connection getConnection(String source) throws SQLException {
61
62
63
64
65 return ((BDAdapter)OpenSync.getInstance().getConfigDoc().
66 getSource(source).getConnector().getAdapter()).getConn();
67 }
68
69 /***
70 * @param source
71 * @param conn
72 * @exception SQLException
73 */
74 static protected void freeConnection(String source, Connection conn) throws SQLException {
75
76
77
78
79 }
80
81 }