/** * Add a document to the document pool. * <p> * This method is intended for internal use only. * * @param doc the root node of the document to be added * @param systemId the document-URI property of this document */ public void registerDocument(DocumentInfo doc, String systemId) { sourceDocumentPool.add(doc, systemId); }
/** * Get the URI for a given document node, if it is present in the pool. This supports the * document-uri() function. * @param doc The document node * @return The uri of the document node, if present in the pool, or the systemId of the document node otherwise */ public String getDocumentURI(NodeInfo doc) { Iterator iter = documentNameMap.keySet().iterator(); while (iter.hasNext()) { String uri = (String)iter.next(); if (find(uri).isSameNodeInfo(doc)) { return uri; } } return null; }
public void update(NodeInfo node, Controller controller) throws XPathException { try { DocumentPool pool = controller.getDocumentPool(); String documentURI = pool.getDocumentURI(node); if (documentURI != null) { QueryResult.rewriteToDisk(node, outputProps, backup, (showTime ? System.err : null)); } else if (showTime) { System.err.println("Updated document discarded because it was not read using doc()"); } } catch (XPathException err) { System.err.println(err.getMessage()); errors.add(err); } } };
/** * Clear the document pool. * This is sometimes useful when re-using the same Transformer * for a sequence of transformations, but it isn't done automatically, because when * the transformations use common look-up documents, the caching is beneficial. */ public void clearDocumentPool() { for (PackageData pack : getExecutable().getPackages()) { sourceDocumentPool.discardIndexes(pack.getKeyManager()); } sourceDocumentPool = new DocumentPool(); }
/** * Remove a document from the document pool. The effect is that the document becomes eligible for * garbage collection, allowing memory to be released when processing of the document has finished. * The downside is that a subsequent call on document() with the same URI causes the document to be * reloaded and reparsed, and the new nodes will have different node identity from the old. * * @param context the evaluation context (supplied implicitly by the call mechanism) * @param doc the document to be released from the document pool * @return the document that was released. This allows a call such as * select="saxon:discard-document(document('a.xml'))" */ public static DocumentInfo discardDocument(XPathContext context, DocumentInfo doc) { if (doc == null) { return null; } Controller c = context.getController(); String uri = c.getDocumentPool().getDocumentURI(doc); if (uri != null) { c.removeUnavailableOutputDestination(uri); } return c.getDocumentPool().discard(doc); }
public boolean docAvailable(String href, XPathContext context) { try { PackageData packageData = getRetainedStaticContext().getPackageData(); DocumentURI documentKey = DocumentFn.computeDocumentKey(href, getStaticBaseUriString(), packageData, context); DocumentPool pool = context.getController().getDocumentPool(); if (pool.isMarkedUnavailable(documentKey)) { return false; } TreeInfo doc = pool.find(documentKey); if (doc != null) { return true; } Item item = DocumentFn.makeDoc(href, getStaticBaseUriString(), packageData, null, context, null, true); if (item != null) { return true; } else { // The document does not exist; ensure that this remains the case pool.markUnavailable(documentKey); return false; } } catch (XPathException e) { return false; } }
/** * Clear the document pool. * This is sometimes useful when re-using the same Transformer * for a sequence of transformations, but it isn't done automatically, because when * the transformations use common look-up documents, the caching is beneficial. */ public void clearDocumentPool() { sourceDocumentPool = new DocumentPool(); }
if (controller.getDocumentPool().contains(doc)) { context.getController().setUserData(doc, "saxon:key-index-list", indexList); } else {
public boolean docAvailable(String href, XPathContext context) { try { PackageData packageData = getRetainedStaticContext().getPackageData(); DocumentURI documentKey = DocumentFn.computeDocumentKey(href, getStaticBaseUriString(), packageData, context); DocumentPool pool = context.getController().getDocumentPool(); if (pool.isMarkedUnavailable(documentKey)) { return false; } TreeInfo doc = pool.find(documentKey); if (doc != null) { return true; } Item item = DocumentFn.makeDoc(href, getStaticBaseUriString(), packageData, null, context, null, true); if (item != null) { return true; } else { // The document does not exist; ensure that this remains the case pool.markUnavailable(documentKey); return false; } } catch (XPathException e) { return false; } }
/** * Remove a document from the document pool. The effect is that the document becomes eligible for * garbage collection, allowing memory to be released when processing of the document has finished. * The downside is that a subsequent call on document() with the same URI causes the document to be * reloaded and reparsed, and the new nodes will have different node identity from the old. * * @param context the evaluation context (supplied implicitly by the call mechanism) * @param doc the document to be released from the document pool * @return the document that was released. This allows a call such as * select="saxon:discard-document(document('a.xml'))" */ public static DocumentInfo discardDocument(XPathContext context, DocumentInfo doc) { if (doc == null) { return null; } Controller c = context.getController(); String uri = c.getDocumentPool().getDocumentURI(doc); if (uri != null) { c.removeUnavailableOutputDestination(uri); } return c.getDocumentPool().discard(doc); }
/** * Clear the document pool. * This is sometimes useful when re-using the same Transformer * for a sequence of transformations, but it isn't done automatically, because when * the transformations use common look-up documents, the caching is beneficial. */ public void clearDocumentPool() { sourceDocumentPool = new DocumentPool(); }
/** * Clear the document pool. * This is sometimes useful when re-using the same Transformer * for a sequence of transformations, but it isn't done automatically, because when * the transformations use common look-up documents, the caching is beneficial. */ public void clearDocumentPool() { for (PackageData pack : getExecutable().getPackages()) { sourceDocumentPool.discardIndexes(pack.getKeyManager()); } sourceDocumentPool = new DocumentPool(); }
if (controller.getDocumentPool().contains(doc)) { context.getController().setUserData(doc, "saxon:key-index-list", indexList); } else {
/** * Get the URI for a given document node, if it is present in the pool. This supports the * document-uri() function. * @param doc The document node * @return The uri of the document node, if present in the pool, or the systemId of the document node otherwise */ public String getDocumentURI(NodeInfo doc) { Iterator iter = documentNameMap.keySet().iterator(); while (iter.hasNext()) { String uri = (String)iter.next(); if (find(uri).isSameNodeInfo(doc)) { return uri; } } return null; }
TreeInfo doc = config.getGlobalDocumentPool().find(documentKey); if (doc != null) { return doc.getRootNode(); doc = pool.find(documentKey); if (doc != null) { return getFragment(doc, fragmentId, c, locator); pool.markUnavailable(documentKey); XPathException err = new XPathException( "Cannot read a document that was written during the same transformation: " + documentKey); if (pool.isMarkedUnavailable(documentKey)) { XPathException err = new XPathException( "Document has been marked not available: " + documentKey); doc = pool.find(documentKey); if (doc != null) { return getFragment(doc, fragmentId, c, locator); pool.markUnavailable(documentKey); XPathException xerr = XPathException.makeXPathException(err); xerr.maybeSetLocation(locator);
public static AnyURIValue getDocumentURI(NodeInfo node, XPathContext c) { if (node.getNodeKind() == Type.DOCUMENT) { Object o = node.getTreeInfo().getUserData("saxon:document-uri"); if (o instanceof String) { return o.toString().isEmpty() ? null : new AnyURIValue(o.toString()); } final Controller controller = c.getController(); assert controller != null; DocumentPool pool = controller.getDocumentPool(); String docURI = pool.getDocumentURI(node); if (docURI == null) { docURI = node.getSystemId(); } if (docURI == null) { return null; } else if ("".equals(docURI)) { return null; } else { return new AnyURIValue(docURI); } } else { return null; } }
/** * Remove a document from the document pool. The effect is that the document becomes eligible for * garbage collection, allowing memory to be released when processing of the document has finished. * The downside is that a subsequent call on document() with the same URI causes the document to be * reloaded and reparsed, and the new nodes will have different node identity from the old. * * @param context the evaluation context (supplied implicitly by the call mechanism) * @param doc the document to be released from the document pool * @return the document that was released. This allows a call such as * select="saxon:discard-document(document('a.xml'))" */ public static DocumentInfo discardDocument(XPathContext context, DocumentInfo doc) { if (doc == null) { return null; } Controller c = context.getController(); String uri = c.getDocumentPool().getDocumentURI(doc); if (uri != null) { c.removeUnavailableOutputDestination(uri); } return c.getDocumentPool().discard(doc); }