1 package org.idpf.epubcheck.util.saxon95; 2 3 import net.sf.saxon.expr.XPathContext; 4 import net.sf.saxon.lib.ExtensionFunctionCall; 5 import net.sf.saxon.lib.ExtensionFunctionDefinition; 6 import net.sf.saxon.om.NodeInfo; 7 import net.sf.saxon.om.Sequence; 8 import net.sf.saxon.om.StructuredQName; 9 import net.sf.saxon.trans.XPathException; 10 import net.sf.saxon.value.AnyURIValue; 11 import net.sf.saxon.value.SequenceType; 12 13 import org.osgi.service.component.annotations.Component; 14 15 @Component( 16 name = "saxon:system-id", 17 service = { ExtensionFunctionDefinition.class } 18 ) 19 public class SystemIdFunction extends ExtensionFunctionDefinition { 20 21 private static final long serialVersionUID = -4202710868367933385L; 22 23 public static StructuredQName QNAME = new StructuredQName("saxon", "http://saxon.sf.net/", "system-id"); 24 25 @Override 26 public StructuredQName getFunctionQName() { 27 return QNAME; 28 } 29 30 @Override 31 public int getMaximumNumberOfArguments() { 32 return 0; 33 } 34 35 @Override 36 public int getMinimumNumberOfArguments() { 37 return 0; 38 } 39 40 @Override 41 public SequenceType[] getArgumentTypes() { 42 return new SequenceType[] {}; 43 } 44 45 @Override 46 public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) { 47 return SequenceType.SINGLE_STRING; 48 } 49 50 @Override 51 public boolean dependsOnFocus() { 52 return true; 53 } 54 55 @Override 56 public boolean trustResultType() { 57 return true; 58 } 59 60 @Override 61 public ExtensionFunctionCall makeCallExpression() { 62 return new ExtensionFunctionCall() { 63 64 private static final long serialVersionUID = -4202710868367933385L; 65 66 public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { 67 if (context.getContextItem() instanceof NodeInfo) { 68 return new AnyURIValue( 69 ((NodeInfo) context.getContextItem()).getSystemId()); 70 } 71 throw new XPathException( 72 "Unexpected XPath context for saxon:system-id"); 73 } 74 }; 75 } 76 }