Project

Profile

Help

Bug #4999 ยป CompileTest.java

Taras Chervinka, 2021-05-25 17:02

 
1
import com.saxonica.config.EnterpriseConfiguration;
2
import com.saxonica.config.ProfessionalConfiguration;
3
import net.sf.saxon.s9api.Processor;
4
import net.sf.saxon.s9api.XQueryCompiler;
5
import net.sf.saxon.s9api.XQueryExecutable;
6
import java.io.*;
7

    
8

    
9
public class CompileTest {
10
   private static String key =
11
         "";
12

    
13

    
14
   private static String deobfuscate(String x) {
15
      String digits = "";
16
      StringBuffer buff = new StringBuffer(x.length());
17
      for (int i = x.length() - 1; i >= 0; i -= 2) {
18
         int c1 = digits.indexOf(x.charAt(i));
19
         int c2 = digits.indexOf(x.charAt(i - 1));
20
         buff.append((char) (c1 << 4 | c2));
21
      }
22
      return buff.toString();
23
   }
24

    
25
   // Activate a ProfessionalConfiguration or EnterpriseConfiguration
26
   public static void activate(ProfessionalConfiguration config) {
27
      config.supplyLicenseKey(new BufferedReader(new StringReader(deobfuscate(key))));
28
   }
29

    
30
   // Activate Saxon at the level of a s9api Processor
31
   public static void activate(Processor processor) {
32
      processor.setConfigurationProperty("http://saxonica.com/oem-data", deobfuscate(key));
33
   }
34

    
35
   public static void testCompile() {
36
      EnterpriseConfiguration pc = new EnterpriseConfiguration();
37
//      ProfessionalConfiguration pc = new ProfessionalConfiguration();
38
      activate(pc);
39
      Processor processor = new Processor(pc);
40
      XQueryCompiler compiler = processor.newXQueryCompiler();
41
      compiler.setLanguageVersion("3.0"); //$NON-NLS-1$
42

    
43
      String expr = "declare variable $selectedService as item()* external;\n"
44
            + "declare variable $wsdlDoc as item()* external;\n"
45
            + "$wsdlDoc/binding[local-name-from-QName(resolve-QName(@type, $wsdlDoc))=$selectedService] \n";
46

    
47
      try{
48
         XQueryExecutable executable = compiler.compile(expr);
49
         System.out.println(pc.toString() + " OK");
50
      } catch (Exception e)
51
      {
52
         e.printStackTrace();
53
      }
54
   }
55

    
56
   public static void main(String[] args) {
57
      testCompile();
58
        }
59
}
    (1-1/1)