| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.PackageData; |
| 11 |
import net.sf.saxon.expr.XPathContext; |
| 12 |
import net.sf.saxon.om.*; |
| 13 |
import net.sf.saxon.trans.XPathException; |
| 14 |
import net.sf.saxon.value.AtomicValue; |
| 15 |
import net.sf.saxon.value.BooleanValue; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public class DocAvailable extends SystemFunction { |
| 22 |
|
| 23 |
private boolean isDocAvailable(AtomicValue hrefVal, XPathContext context) throws XPathException { |
| 24 |
if (hrefVal == null) { |
| 25 |
return false; |
| 26 |
} |
| 27 |
String href = hrefVal.getStringValue(); |
| 28 |
return docAvailable(href, context); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public BooleanValue call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 41 |
return BooleanValue.get(isDocAvailable((AtomicValue) arguments[0].head(), context)); |
| 42 |
} |
| 43 |
|
| 44 |
public boolean docAvailable(String href, XPathContext context) { |
| 45 |
try { |
| 46 |
PackageData packageData = getRetainedStaticContext().getPackageData(); |
| 47 |
DocumentURI documentKey = DocumentFn.computeDocumentKey(href, getStaticBaseUriString(), packageData, context); |
| 48 |
DocumentPool pool = context.getController().getDocumentPool(); |
| 49 |
if (pool.isMarkedUnavailable(documentKey)) { |
| 50 |
return false; |
| 51 |
} |
| 52 |
TreeInfo doc = pool.find(documentKey); |
| 53 |
if (doc != null) { |
| 54 |
return true; |
| 55 |
} |
| 56 |
Item item = DocumentFn.makeDoc(href, getStaticBaseUriString(), packageData, null, context, null, true); |
| 57 |
if (item != null) { |
| 58 |
return true; |
| 59 |
} else { |
| 60 |
|
| 61 |
pool.markUnavailable(documentKey); |
| 62 |
return false; |
| 63 |
} |
| 64 |
} catch (XPathException e) { |
| 65 |
return false; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
} |
| 71 |
|